I'm trying to efficiently change:
[{'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}]
into a list of dictionaries without duplicates and a count of duplicates:
[{'text': 'hallo world', 'num': 2, 'count':1},
{'text': 'hallo world', 'num': 1, 'count':5},
{'text': 'haltlo world', 'num': 1, 'count':1}]
So far, I have the following to find duplicates:
result = [dict(tupleized) for tupleized in set(tuple(item.items()) for item in li)]
and it returns:
[{'text': 'hallo world', 'num': 2},
{'text': 'hallo world', 'num': 1},
{'text': 'haltlo world', 'num': 1}]
THANKS!