Skip to content

Instantly share code, notes, and snippets.

@olivx
Created January 22, 2019 20:09
Show Gist options
  • Save olivx/fe4e305a7dc1882eded0a86c813d6ad8 to your computer and use it in GitHub Desktop.
Save olivx/fe4e305a7dc1882eded0a86c813d6ad8 to your computer and use it in GitHub Desktop.
count item by value in list of dict
import unicodedata
from collections import Counter
list_cand = []
for value in qs:
data ={}
if value['key'] is not None:
word = value['key']
target = unicodedata.normalize('NFKD', word).encode('ASCII','ignore').decode('ASCII').lower().strip()
data['key'] = target
else:
data['key'] = value['key']
list_cand.append(data)
c = Counter()
for _data in list_cand:
c[_data["key"]] += 1
sorted_data = sorted(c.items(), key=lambda x: x[1], reverse=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment