for i in {k: v for k, v in zip(range(10,40,10), range(3))}: # 默认遍历keys()
print(i)
for i in {k: v for k, v in zip(range(10,40,10), range(3))}.items(): # 遍历元组
print(i)
{k: v for k, v in zip(range(10,30,10), range(30))} # 根据键名多少来生成配对,超过键名个数的键值被忽略
10
20
30
(10, 0)
(20, 1)
(30, 2)
{10: 0, 20: 1}
标签:10,20,键名,zip,keys,30,range,键值
From: https://blog.51cto.com/u_16055028/7151581