首页 > 编程语言 > 详细

[Python] zip()

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

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()

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!