码迷,mamicode.com
首页 > 编程语言 > 详细

[Python] zip()

时间:2017-04-11 16:02:06      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:turn   intern   htm   single   nal   uil   bsp   rar   https   

zip() is a built-in function.

zip([iterable, ...])

  

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.

 

Ex:

Input:

X = [1,2,3]
Y = [4,5,6]
zipper = zip(X, Y)

  

Output:

zipper = [(1,4), (2,5), (3,6)]

  

Inversely, we can

x2, y2 = zip(*zipper)

  

x2 == X

y2 == Y

[Python] zip()

标签:turn   intern   htm   single   nal   uil   bsp   rar   https   

原文地址:http://www.cnblogs.com/KennyRom/p/6693869.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!