【发布时间】:2012-07-12 03:05:40
【问题描述】:
这可能是 Python 中的一个经典问题,但我还没有找到答案。
我有一个字典列表,这些字典有相似的键。 它看起来像这样:
[{0: myech.MatchingResponse at 0x10d6f7fd0,
3: myech.MatchingResponse at 0x10d9886d0,
6: myech.MatchingResponse at 0x10d6f7d90,
9: myech.MatchingResponse at 0x10d988ad0},
{0: myech.MatchingResponse at 0x10d6f7b10,
3: myech.MatchingResponse at 0x10d6f7f90>}]
我想获得一个新字典,其中 [0,3,6,9] 作为键,“myech.MatchingResponse”列表作为值。
当然,我可以使用简单的循环来做到这一点,但我想知道是否有更有效的解决方案。
【问题讨论】:
-
反之(从 dict-of-lists 到 list-of-dicts)参见:stackoverflow.com/q/1780174/1959808
标签: python dictionary