python 中实现字典的逆转

 

001、

>>> test1 = dict(c = 500, a = 300, b = 200, e = 600, d = 777)
>>> test1
{'c': 500, 'a': 300, 'b': 200, 'e': 600, 'd': 777}
>>> test2 = dict()
>>> for i,j in reversed(list(test1.items())):     ## 字典逆转
...     test2[i] = j
...
>>> test2
{'d': 777, 'e': 600, 'b': 200, 'a': 300, 'c': 500}

 

posted @ 2022-08-06 14:18  小鲨鱼2018  阅读(43)  评论(0编辑  收藏  举报