深入學習zip() ,能使用列表,元組,但不能使用字典

来源:互联网 发布:中转国际机票 知乎 编辑:程序博客网 时间:2024/06/07 04:20
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)]
原创粉丝点击