简体   繁体   English

访问多个字典值

[英]Accessing multiple dictionary values

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)}}
>>> {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)}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM