for i, j in zip(range(1, 12), range(1, 3)):
print(i, j)
短的列表循环结束后,整个循环停止
同时循环多个列表
for i, j , k in zip(range(1, 12), range(1, 3), range(1, 4)):
print(i, j, k)
for f, b in zip(foo, bar):
print(f, b)
In Python 3, zip returns an iterator of tuples, like itertools.izip in Python2. To get a list of tuples, use list(zip(foo, bar)). And to zip until both iterators are exhausted, you would use itertools.zip_longest.
参考
https://stackoverflow.com/questions/1663807/how-do-i-iterate-through-two-lists-in-parallel