summaryrefslogtreecommitdiff
path: root/wk7/lect/favorites.py
diff options
context:
space:
mode:
authorFudgerboy <91767657+Fudgerboy@users.noreply.github.com>2024-05-20 09:18:46 +0000
committerFudgerboy <91767657+Fudgerboy@users.noreply.github.com>2024-05-20 09:18:46 +0000
commit1ce41b38b2e51078f658eda511ecea23c11a7902 (patch)
treecc2e3ccd60e310632e161480506060fcdb48c5b8 /wk7/lect/favorites.py
parent70fad594167f798b826b580546da1f3934986667 (diff)
Mon, May 20, 2024, 2:18 AM -07:00
Diffstat (limited to 'wk7/lect/favorites.py')
-rw-r--r--wk7/lect/favorites.py11
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])