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}

 

上一篇:CSS 奇思妙想 | Single Div 绘图技巧


下一篇:冬季实战营第四期学习报告