diff options
Diffstat (limited to 'wk7')
-rw-r--r-- | wk7/lect/favorites.py | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/wk7/lect/favorites.py b/wk7/lect/favorites.py index 62ce6c6..fcdc97c 100644 --- a/wk7/lect/favorites.py +++ b/wk7/lect/favorites.py @@ -5,17 +5,16 @@ import csv +from collections import Counter + with open("favorites.csv") as file: reader = csv.DictReader(file) - counts = {} + counts = Counter() for row in reader: favorite = row["language"] - if favorite in counts: - counts[favorite] += 1 - else: - counts[favorite] = 1 + counts[favorite] += 1 -for favorite in sorted(counts, key=counts.get): +for favorite in sorted(counts, key=counts.get, reverse=True): print(favorite, ':', counts[favorite]) |