-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfavorites.py
More file actions
32 lines (22 loc) · 752 Bytes
/
Copy pathfavorites.py
File metadata and controls
32 lines (22 loc) · 752 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import csv
from collections import Counter # initialize
with open("favorites.csv", "r") as file:
reader = csv.DictReader(file)
# counts = {}
# for row in reader:
# favorite = row["language"]
# if favorite in counts:
# counts[favorite] += 1
# else:
# counts[favorite] = 1
counts = Counter()
for row in reader:
favorite = row["problem"]
counts[favorite] += 1
# for favorite, count in counts.most_common():
# print(f"{favorite}: {count}")
# print("*" * 15)
# for favorite in sorted(counts, key=counts.get, reverse=True): # named argument
# print(f"{favorite}: {counts[favorite]}")
favorite = input("Favorite: ")
print(f"{favorite}: {counts[favorite]}")