1.遍历
m = {'a': 1, 'b': 2, 'c': 3}
n = {}
for k, v in m.items():
n[v] = k
print(n)
2.字典推导式
m = {'a': 1, 'b': 2, 'c': 3}
n = {v: k for k, v in m.items()}
print(n)
3.使用zip函数
m = {'a': 1, 'b': 2, 'c': 3}
n = dict(zip(m.values(), m.keys()))
#Python小白学习交流群:725638078
print(n)
4.结合map和reversed函数
m = {'a': 1, 'b': 2, 'c': 3}
n = dict(map(reversed, m.items()))
print(n)
标签:zip,Python,items,value,dict,key,print,字典
From: https://www.cnblogs.com/xxpythonxx/p/17832021.html