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

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



import csv

from collections import Counter

with open("favorites.csv") as file:
    reader = csv.DictReader(file)
    counts = Counter()

    for row in reader:
        favorite = row["language"]
        counts[favorite] += 1

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