I want to count the occurrences of Emojis in a list in python.
Assuming my list looks like this
li = ['😁', '🤣😁', '😁🤣😋']
Counter(li) would give me {'😁': 1, '🤣😁': 1, '😁🤣😋': 1}
But I would like to get the total amount of emojis aka {'😁': 3, '🤣': 2, '😋': 1}
My main issue is how to seperate large chunks of continous emoji into single list entries. I tried with replacing the beginning "\U" with " \U" so i could then simple split by " " but it does not seem to work.
Thanks for your help in advance :)
You can flatten you list into a single string using join and then apply Counter to that:
Counter("".join(li))
results in
Counter({'😁': 3, '🤣': 2, '😋': 1})
or maybe a more memory efficient way is
counter = Counter()
for item in li:
counter.update(item)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With