diff options
author | Fudgerboy <91767657+Fudgerboy@users.noreply.github.com> | 2024-05-20 09:18:46 +0000 |
---|---|---|
committer | Fudgerboy <91767657+Fudgerboy@users.noreply.github.com> | 2024-05-20 09:18:46 +0000 |
commit | 1ce41b38b2e51078f658eda511ecea23c11a7902 (patch) | |
tree | cc2e3ccd60e310632e161480506060fcdb48c5b8 /wk7/lect/favorites.py | |
parent | 70fad594167f798b826b580546da1f3934986667 (diff) |
Mon, May 20, 2024, 2:18 AM -07:00
Diffstat (limited to 'wk7/lect/favorites.py')
-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]) |