In [1]: a = [1, 2, 3]
In [2]: b = ['a,', 'b', 'c']
In [3]: c = [1, 2, 3, 4]
In [4]: zip(a, b) # 返回的是一个对象
Out[4]: <zip at 0x265795f7fc8>
In [5]: list(zip(a, b))
Out[5]: [(1, 'a,'), (2, 'b'), (3, 'c')]
In [6]: list(zip(a, c)) # 元素个数与最少的列表一致
Out[6]: [(1, 1), (2, 2), (3, 3)]
In [7]: a1, b1 = zip(*zip(a, b)) # 解压, 返回两个元组
In [8]: a1
Out[8]: (1, 2, 3)
In [9]: b1
Out[9]: ('a,', 'b', 'c')
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |