python zip

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)]
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容