summaryrefslogtreecommitdiff
path: root/wk7/lect/favorites.py
blob: 62ce6c63e6d601b95719f79967c34e8620be5368 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

# DOESN'T WORK BECAUSE WE DON'T HAVE FAVORITES.CSV



import csv

with open("favorites.csv") 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

for favorite in sorted(counts, key=counts.get):
    print(favorite, ':', counts[favorite])