Last active
April 16, 2018 00:26
-
-
Save uluQulu/cc8b3d09d7a7b1bcf308305979dd1418 to your computer and use it in GitHub Desktop.
code for @belac_
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Build a dictionary containing the specified movie collection | |
movie_dict = { | |
'2005' : [('Munich', 'Steven Speilberg')], | |
'2006' : [('The Prestige', 'Christopher Nolan'), ('The Departed', 'Martin Scorsese')], | |
'2007' : [('Into the Wild', 'Sean Penn')], | |
'2008' : [('The Dark Knight', 'Christopher Nolan')], | |
'2009' : [('Mary and Max', 'Adam Elliot')], | |
'2010' : [('The King\'s Speech', 'Tom Hooper')], | |
'2011' : [('The Artist', 'Michel Hazanavicius'), ('The Help', 'Tate Taylor')], | |
'2012' : [('Argo', 'Ben Affleck')], | |
'2013' : [('12 Years a Slave', 'Steve McQueen')], | |
'2014' : [('Birdman', 'Alejandro G. Inarritu')], | |
'2015' : [('Spotlight', 'Tom McCarthy')], | |
'2016' : [('The BFG', 'Steven Speilberg')], | |
} | |
directors_list = {} | |
for year_i in movie_dict: | |
year = movie_dict.get(year_i) | |
for movie in year: | |
director = movie[1] | |
if director in directors_list: | |
directors_film = (year_i, movie[0]) | |
directors_list[director].insert(0, directors_film) | |
directors_list[director] = sorted(directors_list[director], key=lambda tup: tup[0]) | |
else: | |
directors_list[director] = [] | |
directors_film = (year_i, movie[0]) | |
directors_list[director].insert(0, directors_film) | |
print(directors_list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment