collections 的 OrderedDict 可以解决无序问题,但是他是按照你赋值的顺序实现的,比如我现在有一个 dict
使用 OrderedDict 的话
from collections import OrderedDict
a = OrderedDict()
a["aaa"] = 1
a["bbb"] = 2
这样情况下得出的是一个有序的字典 dict a = {"aaa": 1, "bbb": 2}
如果我原本就有一个 dict b = {"ccc": 3, "ddd": 4}
在不遍历重新赋值的情况下怎样让成为一个有序的字典
使用 OrderedDict 的话
from collections import OrderedDict
a = OrderedDict()
a["aaa"] = 1
a["bbb"] = 2
这样情况下得出的是一个有序的字典 dict a = {"aaa": 1, "bbb": 2}
如果我原本就有一个 dict b = {"ccc": 3, "ddd": 4}
在不遍历重新赋值的情况下怎样让成为一个有序的字典
