Python3-笔记-C-002-函数-zip

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python3-笔记-C-002-函数-zip相关的知识,希望对你有一定的参考价值。

def testzip():
# zip是将每个可迭代对象的对应位置元素打包成一个tuple
# 操作符*zip函数配合可以实现与zip相反的功能, 即将合并的序列拆成多个tuple
# 新的序列的长度以参数中最短的序列为准
x = [1, 2, 3]
y = [4, 5, 6]
z = [7, 8, 9]
xyz = list(zip(x, y, z)) # <class ‘list‘>: [(1, 4, 7), (2, 5, 8), (3, 6, 9)]
x = [1, 2, 3]
y = [4, 5, 6, 7]
xy = list(zip(x, y)) # <class ‘list‘>: [(1, 4), (2, 5), (3, 6)]
x = [1, 2, 3]
x = list(zip(x)) # <class ‘list‘>: [(1,), (2,), (3,)]
x = list(zip()) # <class ‘list‘>: []
x = [1, 2, 3]
y = [4, 5, 6]
z = [7, 8, 9]
xyz = list(zip(x, y, z)) # <class ‘list‘>: [(1, 4, 7), (2, 5, 8), (3, 6, 9)]
u = list(zip(*xyz)) # <class ‘list‘>: [(1, 2, 3), (4, 5, 6), (7, 8, 9)]
x = [1, 2, 3]
r = list(zip(*[x] * 3)) # <class ‘list‘>: [(1, 1, 1), (2, 2, 2), (3, 3, 3)]

# 使用zip反转字典
m = {‘a‘: 1, ‘b‘: 2, ‘c‘: 3, ‘d‘: 4}
m2 = dict(zip(m.values(), m.keys()))
























以上是关于Python3-笔记-C-002-函数-zip的主要内容,如果未能解决你的问题,请参考以下文章

BUU-MISC-[BSidesSF2019]zippy

typescript NGX-易于测试zippy.component.ts

typescript NGX-易于测试zippy.component.spec.ts

mysql学习笔记-day2

python3 基础 笔记记录-3

跟尹成前辈学C/C++ 002