我希望将列表中键为'user'相同的字典合并,但我不知道如何实现。例如:
我在Stack Overflow上进行了广泛搜索,但没有找到类似的内容,希望能得到帮助。非常感谢。
[{'count2': 34, 'user': 2},
{'count4': 233, 'user': 2},
{'count2': 234, 'user': 4},
{'count4': 344, 'user': 5}]
would become:
[{'count2': 34, 'count4': 233, 'user': 2 },
{'count2': 234, 'user': 4},
{'count4': 344, 'user': 5}]
我在Stack Overflow上进行了广泛搜索,但没有找到类似的内容,希望能得到帮助。非常感谢。
{2:{'count2':34 ...},4:{'count2':234 ...}
等等。这样更加直观,并且构建起来可能更容易些。 - David Robinson