zip 使用

>>> z = [(1,2),(3,"d"),(4,"e")]

>>> z

[(1, 2), (3, 'd'), (4, 'e')]

>>> zip(*z)

<zip object at 0x101aae248>

 

>>> for i in zip(*z):

...     print(i)

... 

(1, 3, 4)

(2, 'd', 'e')

>>> z

[(1, 2), (3, 'd'), (4, 'e')]

>>> l = (1,2,3)

>>> l2= (3,4,5)

>>> zip(l,l2)

<zip object at 0x101aae248>

>>> for i in zip(l,l2):

...     print(i)

... 

(1, 3)

(2, 4)

(3, 5)

posted @ 2017-03-10 01:06  王喜山  阅读(118)  评论(0编辑  收藏  举报