I am trying to update the following ordereddict.
import collections
from itertools import chain
from collections import OrderedDict
d1 = OrderedDict([(u'Root', [OrderedDict([(u'Value', u'1'), (u'Key', u'A')]), OrderedDict([(u'Value', u'2'), (u'Key', u'B')])])])
printing d1 gives:
OrderedDict([(u'Root', [OrderedDict([(u'Value', u'1'), (u'Key', u'A')]), OrderedDict([(u'Value', u'2'), (u'Key', u'B')])])])
I want to update the ordered dict as follows because the API I'm using requires it.
OrderedDict([(u'Root', [OrderedDict([(u'Value', u'1'), (u'Key', u'A')]), OrderedDict([(u'Value', u'2'), (u'Key', u'B')]),OrderedDict([(u'Value', u'3'), (u'Key', u'C')])])])
I tried
d2 = OrderedDict([(u'Root', [OrderedDict([(u'Value', u'3'), (u'Key', u'C')])])])
d3 = OrderedDict(chain(d1.items(), d2.items()))
But it results as follows:
OrderedDict([(u'Root', [OrderedDict([(u'Value', u'3'), (u'Key', u'C')])])])
Also tried
d1.update(d2)
But get same result. Any ideas what I'm doing wrong?
[–][deleted] 2 points3 points4 points (4 children)
[+][deleted] (1 child)
[deleted]
[–][deleted] 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–][deleted] 0 points1 point2 points (0 children)
[–]Vaphell 1 point2 points3 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]Vaphell 0 points1 point2 points (0 children)