首页 > 代码库 > [Python] zip()
[Python] zip()
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()
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。