相关疑难解决方法(0)

python词典列表根据值查找重复项

我在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)

我希望我很清楚

非常感谢你的建议

python dictionary loops list

7
推荐指数
2
解决办法
5284
查看次数

标签 统计

dictionary ×1

list ×1

loops ×1

python ×1