For a loop with multiple conditions in Python

I have 3 lists of equal sizes (List1,2 and 3). I want to iterate through a list and perform operations on each of the elements. how

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 

So, I want to go through the list only for "Length of List1 or 2 or size", and then perform operations on x, y and z. How can I do this using Python?

Edit: Python version 2.6.6

+4
source share
2 answers
 import itertools for x, y, z in itertools.izip(List1, List2, List3): # ... 

Or just zip in Python 3.

+8
source
 >>> map(lambda x, y, z: (x, y, z), range(0, 3), range(3, 6), range(6, 9)) [(0, 3, 6), (1, 4, 7), (2, 5, 8)] 
0
source

Source: https://habr.com/ru/post/1381470/


All Articles