Guest User

Untitled

a guest
Dec 18th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. year:
  2. title, director
  3.  
  4. title:
  5. director, year
  6.  
  7. director:
  8. title, year
  9.  
  10. movie_dict = {
  11. '2015': [['Splotlight', 'Tom MacCarthy'], ['Timbuktu', 'Abderrahmane Sissako']],
  12. '2005': [['Munich', 'Steven Spielberg'],
  13. ['Star Wars: Episode III - Revenge of the Sith', 'George Lucas'],
  14. ['Batman Begins', 'Christopher Nolan']],
  15. '2006': [['The Prestige', 'Christopher Nolan'],
  16. ['The Departed', 'Martin Scorsese']],
  17. '2007': [['Into the Wild', 'Sean Penn']],
  18. '2008': [['The Dark Knight', 'Christopher Nolan']],
  19. '2009': [['Mary and Max', 'Adam Elliot']],
  20. '2010': [['The King's Speech', 'Tom Hooper']],
  21. '2011': [['The Artist', 'Michel Hazanaviscius'], ['The Help', 'Tate Taylor']],
  22. '2012': [['Argo', 'Ben Afflect']],
  23. '2013': [['12 Years a Slave', 'Steve McQueen']],
  24. '2014': [['Birdman', 'Alejandro G. Inarritu']],
  25. '2016': [['The BFG', 'Steven Spielberg']],
  26. }
  27.  
  28. # sort by year, sort by Title if multiple movies within a year
  29. print('Movies by Year')
  30. for year, movie_list in sorted(movie_dict.items(), key=lambda year: year[0]):
  31. print(year + ': ')
  32. for title, director in sorted(movie_list, key=lambda x: x[0]):
  33. print('t' + title + ', ' + director)
  34.  
  35.  
  36. title_dict = {movie[0]: (movie[1], year)
  37. for year, movies in movie_dict.items()
  38. for movie in movies}
  39.  
  40. # sort by title
  41. print('nnMovies by title')
  42. for title, movie in sorted(title_dict.items(), key=lambda title: title[0]):
  43. print(title + ': ')
  44. print('t' + movie[0] + ', ' + movie[1])
  45.  
  46. director_dict = {}
  47. for year, movie_list in movie_dict.items():
  48. for title, director in movie_list:
  49. if director not in director_dict:
  50. director_dict[director] = []
  51. director_dict[director].append([title, year])
  52.  
  53. # sort by director, if multiple title then sort by year
  54. for director, movie_list in sorted(director_dict.items(), key=lambda x: x[0]):
  55. print(director + ': ')
  56. for title, year in sorted(movie_list, key=lambda x: x[1]):
  57. print('t' + title + ', ' + year)
  58.  
  59. Movies by Year
  60. 2005:
  61. Batman Begins, Christopher Nolan
  62. Munich, Steven Spielberg
  63. Star Wars: Episode III - Revenge of the Sith, George Lucas
  64. 2006:
  65. The Departed, Martin Scorsese
  66. The Prestige, Christopher Nolan
  67.  
  68. Movies by title
  69. 12 Years a Slave:
  70. Steve McQueen, 2013
  71. Argo:
  72. Ben Afflect, 2012
  73. Batman Begins:
  74. Christopher Nolan, 2005
  75. Birdman:
  76. Alejandro G. Inarritu, 2014
  77.  
  78. Ben Afflect:
  79. Argo, 2012
  80. Christopher Nolan:
  81. Batman Begins, 2005
  82. The Prestige, 2006
  83. The Dark Knight, 2008
Add Comment
Please, Sign In to add comment