looping through multiple lists

Posted vivivi

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了looping through multiple lists相关的知识,希望对你有一定的参考价值。

map: 最大长度输出;
zip: 最短输出;
third: 有序排列;

a = ['a1', 'a2', 'a3']
b = ['b1', 'b2']

print "Map:"
for x, y in map(None, a, b):
  print x, y

# will iterate 2 times,
# the third value of a will not be used
print "Zip:"
for x, y in zip(a, b):
  print "{0}, {1}".format(x, y)

# will iterate 6 times,
# it will iterate over each b, for each a
# producing a slightly different outpu
print "List:"
for x, y in [(x,y) for x in a for y in b]:
    print x, y
================= RESTART: /Users/vivi/Documents/multlist.py =================
Map:
a1 b1
a2 b2
a3 None
Zip:
a1, b1
a2, b2
List:
a1 b1
a1 b2
a2 b1
a2 b2
a3 b1
a3 b2

以上是关于looping through multiple lists的主要内容,如果未能解决你的问题,请参考以下文章

Symfony fos:user:create through error "could not find driver", (Xampp with multiple versio

csharp 来自https://stackoverflow.com/questions/874380/wpf-how-do-i-loop-through-the-all-controls-in-a-

USACO 4.1 Fence Loops(Floyd求最小环)

For Loop 没有正确应用 nth-child

across cross through pass的区别

walk through和 across有啥区别