私は効率的に変更しようとしています:
[{'text': 'hallo world', 'num': 1},
{'text': 'hallo world', 'num': 2},
{'text': 'hallo world', 'num': 1},
{'text': 'haltlo world', 'num': 1},
{'text': 'hallo world', 'num': 1},
{'text': 'hallo world', 'num': 1},
{'text': 'hallo world', 'num': 1}]
重複のない辞書のリストと重複の数に:
[{'text': 'hallo world', 'num': 2, 'count':1},
{'text': 'hallo world', 'num': 1, 'count':5},
{'text': 'haltlo world', 'num': 1, 'count':1}]
これまでのところ、重複を見つけるために次のものがあります。
result = [dict(tupleized) for tupleized in set(tuple(item.items()) for item in li)]
そしてそれは戻ります:
[{'text': 'hallo world', 'num': 2},
{'text': 'hallo world', 'num': 1},
{'text': 'haltlo world', 'num': 1}]
ありがとう!