zip

 

>>> s = 'abc'
>>> t = [0, 1, 2]
>>> zip(s, t)
<zip object at 0x7f7d0a9e7c48>
The result is a zip object that knows how to iterate through the pairs. The most common use of zip is in a for loop:
>>> for pair in zip(s, t):
...     print(pair)
...
('a', 0)
('b', 1)
('c', 2)
If you want to use list operators and methods, you can use a zip object to make a list:
>>> list(zip(s, t))
[('a', 0), ('b', 1), ('c', 2)]

 

posted @ 2018-12-18 11:22  anobscureretreat  阅读(240)  评论(0编辑  收藏  举报