@@ -16,12 +16,14 @@ def get_movies_by_director():
16
16
reader = csv .DictReader (f )
17
17
d = defaultdict (list )
18
18
for row in reader :
19
- director = row ["director_name" ]
20
- title = row ["movie_title" ].replace ("\xa0 " , "" )
21
- year = row ["title_year" ]
22
- score = float (row ["imdb_score" ])
23
- if director :
24
- d [director ].append (Movie (title = title , year = year , score = score ))
19
+ try :
20
+ director = row ["director_name" ]
21
+ title = row ["movie_title" ].replace ("\xa0 " , "" )
22
+ year = int (row ["title_year" ])
23
+ score = float (row ["imdb_score" ])
24
+ except ValueError :
25
+ continue
26
+ d [director ].append (Movie (title = title , year = year , score = score ))
25
27
return d
26
28
27
29
@@ -39,12 +41,14 @@ def get_average_scores(directors):
39
41
)
40
42
return sd
41
43
44
+
42
45
def _year_sort (movies ):
43
46
for count , movie in enumerate (movies ):
44
- if not int ( movie .year ) > MIN_YEAR :
45
- del ( movies [count ])
47
+ if not movie .year > MIN_YEAR :
48
+ del movies [count ]
46
49
return movies
47
50
51
+
48
52
def _calc_mean (movies ):
49
53
"""Helper method to calculate mean of list of Movie namedtuples"""
50
54
score = 0
@@ -57,7 +61,7 @@ def print_results(directors):
57
61
"""Print directors ordered by highest average rating. For each director
58
62
print his/her movies also ordered by highest rated movie.
59
63
See http://pybit.es/codechallenge13.html for example output"""
60
- directors = dict (list (directors .items ())[:10 ])
64
+ directors = dict (list (directors .items ())[:20 ])
61
65
fmt_director_entry = "{counter:02}. {director:<52} {avg}"
62
66
fmt_movie_entry = "{year} {title:<50} {score}"
63
67
sep_line = "-" * 60
0 commit comments