pythonbook/Python 基础教程/1.7.1 B字典推导式.py

11 lines
218 B
Python

value = [1, 2, 3, 4, 5]
key = ['a', 'b', 'c', 'd', 'e']
dic = {k:v for k,v in zip(key,value)}
print(dic)
dic = {k:v+1 for v,k in enumerate(key)}
print(dic)
dic = {key[i]:value[i] for i in range(len(key))}
print(dic)