Permalink
Switch branches/tags
Find file Copy path
85dfcf4 Apr 2, 2017
1 contributor

Users who have contributed to this file

47 lines (32 sloc) 1.26 KB
import csv
from collections import defaultdict, namedtuple
MOVIE_DATA = 'movie_metadata.csv'
NUM_TOP_DIRECTORS = 20
MIN_MOVIES = 4
MIN_YEAR = 1960
Movie = namedtuple('Movie', 'title year score')
def get_movies_by_director():
'''Extracts all movies from csv and stores them in a dictionary
where keys are directors, and values is a list of movies (named tuples)'''
pass
def get_average_scores(directors):
'''Filter directors with < MIN_MOVIES and calculate averge score'''
pass
def _calc_mean(movies):
'''Helper method to calculate mean of list of Movie namedtuples'''
pass
def print_results(directors):
'''Print directors ordered by highest average rating. For each director
print his/her movies also ordered by highest rated movie.
See http://pybit.es/codechallenge13.html for example output'''
fmt_director_entry = '{counter}. {director:<52} {avg}'
fmt_movie_entry = '{year}] {title:<50} {score}'
sep_line = '-' * 60
def main():
'''This is a template, feel free to structure your code differently.
We wrote some tests based on our solution: test_directors.py'''
directors = get_movies_by_director()
directors = get_average_scores(directors)
print_results(directors)
if __name__ == '__main__':
main()