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.
這個函數返回一個元組列表,其中第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)]
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容