summaryrefslogtreecommitdiff
path: root/wk7/lect/favorites.py
diff options
context:
space:
mode:
authorFudgerboy <91767657+Fudgerboy@users.noreply.github.com>2024-05-20 09:12:37 +0000
committerFudgerboy <91767657+Fudgerboy@users.noreply.github.com>2024-05-20 09:12:37 +0000
commitaf45c563be4e7cfa6d5e003a7470ec024d0a4bcd (patch)
treed468a649c7edeeba57b69940eae570f8cbf6655e /wk7/lect/favorites.py
parentddc5f732b1a54934fadecdd85bd7764203d7034b (diff)
Mon, May 20, 2024, 2:12 AM -07:00
Diffstat (limited to 'wk7/lect/favorites.py')
-rw-r--r--wk7/lect/favorites.py20
1 files changed, 10 insertions, 10 deletions
diff --git a/wk7/lect/favorites.py b/wk7/lect/favorites.py
index 289a17f..446a92e 100644
--- a/wk7/lect/favorites.py
+++ b/wk7/lect/favorites.py
@@ -7,15 +7,15 @@ import csv
with open("favorites.csv") as file:
reader = csv.DictReader(file)
- scratch, c, python = 0, 0, 0
+ counts = {}
for row in reader:
- favorite = row['language']
- if favorite == "Scratch":
- scratch += 1
- elif favorite == "C":
- c += 1
- elif favorite == "Python":
- python += 1
-
-print("Scratch:", scratch)
+ favorite = row["language"]
+ if favorite in counts:
+ counts[favorite] += 1
+ else:
+ counts[favorite] = 1
+
+for favorite in counts:
+ print(favorite, ':', counts[favorite])
+