Zip函数(Python)

>>> z = zip((2,3,4),(33,44,55))
>>> z
<zip object at 0x1022cdb88>
>>> list(z)
[(2, 33), (3, 44), (4, 55)]

要注意 ** zip 也是_one-pass iterator** !被遍历一次之后会自动_消失_。

zip类型支持list,next等:

>>> z = zip((2,3,4),(33,44,55))
>>> next(z)
(2, 33)
>>> next(z)
(3, 44)
>>> next(z)
(4, 55)
>>> next(z)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
StopIteration
原文地址:https://www.cnblogs.com/yaos/p/6985627.html