import collections
from itertools import chain
from collections import OrderedDict
a = OrderedDict([('a', 1), ('b', 2)])
b = OrderedDict([('c', 1), ('d', 2)])
e = OrderedDict(chain(a.items(), b.items()))
print(e, a, b)
a.update(b)
print(a)
d1 = collections.OrderedDict([('a', 1), ('b', 2)])
d2 = collections.OrderedDict([('c', 1), ('d', 2)])
d3 = collections.OrderedDict(list(d1.items()) + list(d2.items()))
print(d3)
python合并有序字典OrderedDict
最新推荐文章于 2024-07-08 15:56:31 发布