Skip to content

Instantly share code, notes, and snippets.

@valeriocos
Created June 7, 2020 16:42
Show Gist options
  • Save valeriocos/424ffc2fe9057215992842ed9a0d44ee to your computer and use it in GitHub Desktop.
Save valeriocos/424ffc2fe9057215992842ed9a0d44ee to your computer and use it in GitHub Desktop.
using counter to count emotions
import collections
def __get_reactions(self, item):
item_reactions = item.get('award_emoji_data', [])
if item_reactions:
reactions_counter = collections.Counter([reaction["name"] for reaction in item_reactions])
item_reactions = [{"type": reaction, "count": reactions_counter[reaction]} for reaction in reactions_counter]
return {"reactions": item_reactions}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment