Question

I have two dictionaries in the below format

    d=defaultdict(<class 'collections.OrderedDict'>, {u'1': OrderedDict([(1746L, 1), (2239L, 1)]), u'2': OrderedDict([(1965L, 2)]),u'3': OrderedDict([(2425L, 1),(2056L, 4)])})  

    e={2056L: 3, 1746L: 3, 2239L: 2, 1965L: 3, 2425L: 4}

How can i create another dictionary which is of this format??

    {u'1':{1746L:(1,3),2239L:(1,2)},u'2':{1965L:(2,3)},u'3':{2425L:(1,4),2056L(4,3)}}
Was it helpful?

Solution

>>> {i: {j: (d[i][j], e[j]) for j in d[i]} for i in d}
{u'1': {1746L: (1, 3), 2239L: (1, 2)}, u'3': {2056L: (4, 3), 2425L: (1, 4)}, u'2': {1965L: (2, 3)}}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top