python学习-32 zip函数
程序员文章站
2023-04-05 16:13:58
zip 拉链方法 例如:1. 运行结果: 2. 运行结果: 3. 运行结果: ......
zip 拉链方法
例如:1.
print(list(zip(('a','n','c'),('1','2','3'))))
运行结果:
[('a', '1'), ('n', '2'), ('c', '3')] process finished with exit code 0
2.
a = {'name':'abc','age':18,'address':'bj'} print(list(zip(a.keys(),a.values())))
运行结果:
[('name', 'abc'), ('age', 18), ('address', 'bj')] process finished with exit code 0
3.
print(list(zip(('abcdefg'),('1234567'))))
运行结果:
[('a', '1'), ('b', '2'), ('c', '3'), ('d', '4'), ('e', '5'), ('f', '6'), ('g', '7')] process finished with exit code 0