Python中for循环如何同时迭代多个对象

2017-08-17  本文已影响0人  我有一只碗

同时迭代多个对象分为两种情况

# 并行
chinese = [randint(60, 100) for _ in range(40)]
math = [randint(60, 100) for _ in range(40)]
english = [randint(60, 100) for _ in range(40)]
total = []
for x, y, z in zip(chinese, math, english):
    total.append(x + y + z)
# 串行
class1 = [randint(60, 100) for _ in range(40)]
class2 = [randint(60, 100) for _ in range(40)]
class3 = [randint(60, 100) for _ in range(40)]
l = filter(lambda x: x >= 80, chain(class1, class2, class3))
上一篇 下一篇

猜你喜欢

热点阅读