如何在字典列表中替换所有字典(每个字典具有相同或不同值的相同键)with same values of keys id and type which occur more than 0ne time with just one new dictionary with type group
?我可以通过迭代计数存在并将所有组合与多个存在和替换放入列表中,但是有更快的方法吗?
[{id:1, type:1, content:'txt'},{id:2, type:1, content:'abc'},{id:1, type:1, content:'yup'},{id:1, type:1, content:'dmg'}]
会变成
[{id:1, type:'group', content:'txt'},{id:2, type:1, content:'abc'}]