Created
January 22, 2019 20:09
-
-
Save olivx/fe4e305a7dc1882eded0a86c813d6ad8 to your computer and use it in GitHub Desktop.
count item by value in list of dict
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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