欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

python 内建函数 zip

程序员文章站 2022-06-19 10:48:53
key = [key for key in dict(zip(('a','b','c','d','e'),(1,2,3,4,5))) ] print(key) ['a', 'b', 'c', 'd', 'e'] A0 = dict(zip(('a','b','c','d','e'),(1,2,3,4 ......
key = [key for key in dict(zip(('a','b','c','d','e'),(1,2,3,4,5))) ]
print(key)
--------------------------------------------------------
['a', 'b', 'c', 'd', 'e']
 
a0 = dict(zip(('a','b','c','d','e'),(1,2,3,4,5)))
a1 = range(10)
a2 = [i for i in a1 if i in a0]
a3 = [a0[s] for s in a0]
a4 = [i for i in a1 if i in a3]
a5 = {i:i*i for i in a1}
a6 = [[i,i*i] for i in a1]
-------------------------------------------------------------
a0 = {'a': 1, 'c': 3, 'b': 2, 'e': 5, 'd': 4}
a1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
a2 = []
a3 = [1, 3, 2, 5, 4]
a4 = [1, 2, 3, 4, 5]
a5 = {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81}
a6 = [[0, 0], [1, 1], [2, 4], [3, 9], [4, 16], [5, 25], [6, 36], [7, 49], [8, 64], [9, 81]]



本文首发于python黑洞网,博客园同步跟新