This function returns a list of tuples, where the i-th tuple contains the i-th element from each of the argument sequences or iterables.
这个函数返回一个元组列表,其中第i个元组包含每个参数序列或iterables中的i - th元素。
The returned list is truncated in length to the length of the shortest argument sequence. When there are multiple arguments which are all of the same length, [zip()
](#zip) is similar to [map()
](#map) with an initial argument of None
.
返回的列表长度被缩短为最短的参数序列的长度。当有多个相同长度的参数时,zip()类似于map(),初始参数为None。
With a single sequence argument, it returns a list of 1-tuples. With no arguments, it returns an empty list.
使用一个序列参数,它返回1元组的列表。没有参数,它返回空列表。
注意是元组的列表
>>> x=[1,2,3,]
>>> y=zip(x)
>>> y
[(1,), (2,), (3,)]
zip()
in conjunction with the *
operator can be used to unzip a list:
使用*来unzip
注意:只是又把他们放到一块了,外面多了个方括号的
>>> x=[1,2,3,]
>>> y=zip(x)
>>> zip(*y)
[(1, 2, 3)]
>>> zip(*y*3)
[(1, 2, 3, 1, 2, 3, 1, 2, 3)]