#字典推导式创建
key_value=["hello","nihao"]
my_dict={key:len(key) for key in key_value}
print(my_dict)
#交换字典中的键和值
my_dict1={'数学':90,'英文':89}
my_dict2={v:k for k,v in my_dict1.items()}
print(my_dict2)
运行结果为:
{'hello': 5, 'nihao': 5}
{90: '数学', 89: '英文'}