编程语言
首页 > 编程语言> > python中实现字典的逆向排列

python中实现字典的逆向排列

作者:互联网

 

1、

>>> a = dict(a = 111, b = 222, c = 333, d = 444)
>>> for i in reversed(a):    ## 逆向输出
    print(i,a[i])

    
d 444
c 333
b 222
a 111

 

2、

>>> a
{'a': 111, 'b': 222, 'c': 333, 'd': 444}
>>> b = {}
>>> for i in reversed(a):
    b[i] = a[i]

    
>>> b
{'d': 444, 'c': 333, 'b': 222, 'a': 111}

 

标签:逆向,python,reversed,333,444,111,222,字典
来源: https://www.cnblogs.com/liujiaxin2018/p/14450752.html