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. 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() is similar to map() with an initial argument of None. With a single sequence argument, it returns a list of 1-tuples. With no arguments, it returns an empty list.
The left-to-right evaluation order of the iterables is guaranteed. This makes possible an idiom for clustering a data series into n-length groups using zip(*[iter(s)]*n).
zip() in conjunction with the * operator can be used to unzip a list:
Formerly, zip() required at least one argument and zip() raised a TypeError instead of returning an empty list.
zip()是Python的一個內建函數,它接受一系列可迭代的對象作為參數,將對象中對應的元素打包成一個個tuple(元組),然後返回由這些tuples組成的list(列表)。若傳入參數的長度不等,則返回list的長度和參數中長度最短的對象相同。利用*號操作符,可以將list unzip(解壓)
zip函數接受任意多個序列作為參數,將所有序列按相同的索引組合成一個元素是各個序列合併成的tuple的新序列,新的序列的長度以參數中最短的序列為準。另外(*)操作符與zip函數配合可以實現與zip相反的功能,即將合併的序列拆成多個tuple。
①tuple的新序列
②新的序列的長度以參數中最短的序列為準.
③(*)操作符與zip函數配合可以實現與zip相反的功能,即將合併的序列拆成多個tuple
本項目歡迎各位Pythoner踴躍投稿,郵箱:sinoandywong@gmail.com。更多Python乾貨歡迎關注微信公眾號、知乎專欄:Python中文社區,致力於成為國內最好的Python開發者學習交流平臺,這裡有關於Python的國內外最新消息,每日推送有趣有料的技術乾貨和社區動態。
Python中文社區微信公眾號:
Python中文社區QQ交流群:
Python各專業技術QQ交流群:
Python中文社區:309365624
Python中文社區Git項目組:
477542380
Python網絡爬蟲組:206241755
Python數據分析挖掘組:539956362
Python高級技術交流:273186166
PythonWeb開發組:577672548
Python樹莓派組:338456791
Python滲透測試組:274631467
Python量化交易策略組:264204289
Python自然語言處理組: 570364809
微信公眾號:Python中文社區
知乎專欄:Python中文社區