【发布时间】:2016-04-10 11:27:50
【问题描述】:
这里的任何人都知道如何在 python 中更改顺序字典变量的顺序。 我试图改变键列表的顺序,但它没有改变字典的顺序。
例如我想改变 d
的顺序
改为 ['e','a','b','c','d'] 而不是 ['a','b','c','d','e']
d = collections.OrderedDict()
d['a'] = 'A'
d['b'] = 'B'
d['c'] = 'C'
d['d'] = 'D'
d['e'] = 'E'
【问题讨论】:
标签: python dictionary indexing