一条语句实现Python字典 key 和 value 对调

程序实现:

a = {1:'a',2:'b',3:'c'}

b = {value:key for key,value in a.items()}

print(b)

运行结果:

{'a': 1, 'b': 2, 'c': 3}

猜你喜欢

转载自blog.csdn.net/qq_42067550/article/details/106084919
今日推荐