对于Python中具有多个条件的循环

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

Cat*_*lus 8

import itertools
for x, y, z in itertools.izip(List1, List2, List3):
    # ...
Run Code Online (Sandbox Code Playgroud)

或者只是zip在Python 3中.

  • `itertools`包含在Python 2.6中,你只需要导入它. (2认同)