假设我有两个列表,foo
和bar
实例如下:如何一次迭代两个列表?
foo = ['Hello', 'Yes', 'No']
bar = ['Bonjour', 'Oui', 'Non']
假设,那么,我想通过数值迭代和打印像这样的连接:
count = 0
for x in foo:
print x + bar[count]
count += 1
这将使我:
HelloBonjour
YesOui
NONON
会不会有,不会要求计数iterator方法?也许沿着...
for x in foo and y in bar:
pint x + y
可用?
+1拉链。如果你运行的是较旧版本的python(<3),应该注意''itertools.izip()'将会这样做。默认情况下,当前版本的python似乎是懒惰的。 – KChaloux
具体而言,Python 3.x很懒。 Python 2.7仍然是最新的:) – chepner