Syn*_*ter 4 python for-loop python-2.x
我有3个相同大小的列表(List1,2和3).我想遍历列表并对每个项执行操作.喜欢
for x in List1, y in List2, z in List3:
if(x == "X" or x =="x"):
//Do operations on y
elif(y=="Y" or y=="y"):
//Do operations on x,z
Run Code Online (Sandbox Code Playgroud)
所以我想仅为"List1或2的长度或大小"遍历列表,然后对x,y和z执行操作.我怎么能用Python做到这一点?
编辑:Python版本2.6.6
import itertools
for x, y, z in itertools.izip(List1, List2, List3):
# ...
Run Code Online (Sandbox Code Playgroud)
或者只是zip在Python 3中.
| 归档时间: |
|
| 查看次数: |
8157 次 |
| 最近记录: |