Skip to content

Commit 9437882

Browse files
author
Calvin Gutierrez
committed
challenge
1 parent 840b6cb commit 9437882

File tree

5 files changed

+5090
-6
lines changed

5 files changed

+5090
-6
lines changed

days/04-06-collections/challenge.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import csv
2+
from collections import defaultdict, namedtuple
3+
import os
4+
from urllib.request import urlretrieve
5+
6+
movie_data = 'https://raw.githubusercontent.com/pybites/challenges/solutions/13/movie_metadata.csv'
7+
movie_csv = 'movie.csv'
8+
urlretrieve(movie_data, movie_csv)
9+
Movie = namedtuple('Movie', 'title year score')
10+
11+
12+
def get_movies_by_director(data=movie_csv):
13+
"""Extracts all movies from csv and stores them in a dictionary
14+
where keys are directors, and values is a list of movies (named tuples)"""
15+
directors = defaultdict(list)
16+
with open(data, encoding='utf-8') as file:
17+
for line in csv.DictReader(file):
18+
pass
19+
20+
21+
22+
23+
# def calc_mean_score(movies):
24+
# """Helper method to calculate mean of list of Movie namedtuples,
25+
# round the mean to 1 decimal place"""
26+
# pass
27+
#
28+
#
29+
# def get_average_scores(directors):
30+
# """Iterate through the directors dict (returned by get_movies_by_director),
31+
# return a list of tuples (director, average_score) ordered by highest
32+
# score in descending order. Only take directors into account
33+
# with >= MIN_MOVIES"""
34+
# pass
35+
get_movies_by_director()

0 commit comments

Comments
 (0)