colors = ['red', 'green', 'blue']
values = [2, 3, 5, 6]
zip(colors, values)
# [('red', 2), ('green', 3), ('blue', 5)]
dots = [(1, 2), (3, 4), (5, 6)]
x, y = zip(*dots)
# x
# (1, 3, 5)
# y
# (2, 4, 6)
seq = range(1, 10)
zip(*[iter(seq)] * 3)
# [(1, 2, 3), (4, 5, 6), (7, 8, 9)]
x = iter(range(1, 10))
zip(x, x, x) # zip可以直接操作迭代器
# [(1, 2, 3), (4, 5, 6), (7, 8, 9)]
深入學習zip() ,能使用列表,元組,但不能使用字典
最新推荐文章于 2024-07-20 17:12:48 发布