我在python 2.7中有一个dicts列表.
a =[{'id': 1,'desc': 'smth'},
{'id': 2,'desc': 'smthelse'},
{'id': 1,'desc': 'smthelse2'},
{'id': 1,'desc': 'smthelse3'},....]
Run Code Online (Sandbox Code Playgroud)
我想通过列表找到那些具有相同值的dicts - id(例如id = 1)并创建一个新的dict
b = [{'id':1, 'desc' : [smth, smthelse2,smthelse3]},
{'id': 2, 'desc': 'smthelse'}]
Run Code Online (Sandbox Code Playgroud)
我希望我很清楚
非常感谢你的建议