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.
這個函數(shù)返回一個元組列表,其中第i個元組包含每個參數(shù)序列或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
.
返回的列表長度被縮短為最短的參數(shù)序列的長度。當(dāng)有多個相同長度的參數(shù)時,zip()類似于map(),初始參數(shù)為None。
With a single sequence argument, it returns a list of 1-tuples. With no arguments, it returns an empty list.
使用一個序列參數(shù),它返回1元組的列表。沒有參數(shù),它返回空列表。
注意是元組的列表
>>> 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)]