Question
Code: movieCollectionDict = {Munich:[2005, Steven Spielberg], The Prestige: [2006, Christopher Nolan], The Departed: [2006, Martin Scorsese], Into the Wild: [2007, Sean Penn], The Dark Knight:
Code:
movieCollectionDict = {"Munich":[2005, "Steven Spielberg"], "The Prestige": [2006, "Christopher Nolan"], "The Departed": [2006, "Martin Scorsese"], "Into the Wild": [2007, "Sean Penn"], "The Dark Knight": [2008, "Christopher Nolan"], "Mary and Max": [2009, "Adam Elliot"], "The King's Speech": [2010, "Tom Hooper"], "The Artist": [2011, "Michel Hazanavicius"], "The Help": [2011, "Tate Taylor"], "Argo": [2012, "Ben Affleck"], "12 Years a Slave": [2013, "Steve McQueen"], "Birdman": [2014, "Alejandro G. Inarritu"], "Spotlight": [2015, "Tom McCarthy"], "The BFG": [2016, "Steven Spielberg"] } promptForGivenYear = True while promptForGivenYear: userchoiceOfMovie = int(input("Enter a year between 2005 and 2016: ")) if userchoiceOfMovie 2016: print("N/A") else: for key, value in movieCollectionDict.items(): if value[0] == userchoiceOfMovie: print(key + ", " + str(value[1])) promptForGivenYear = False # Display menu
menu = " MENU" " Sort by:" " y - Year" " d - Director" " t - Movie title" " q - Quit"
userchoiceOfMovie = True while userchoiceOfMovie: print(menu)
userChoice = str(input(" Choose an option: ")) if userChoice == "q": userchoiceOfMovie = False elif userChoice == "y": year_sorted = {} for key, value in sorted(movieCollectionDict.items(), key=lambda item: (item[1], item[0])): year = value[0] title = key director = value[1] if year not in year_sorted: year_sorted[year] = [[title, director]] else: year_sorted[year].append([title, director]) for year in sorted(year_sorted): print (str(year) + ":") movies = year_sorted[year] for movie in sorted(movies, key=lambda x: x[0]): print(" " + movie[0] + ", " + movie[1]) elif userChoice == "d": director_sorted = {} for key, value in sorted(movieCollectionDict.items(), key=lambda item: (item[1][1])): year = value[0] title = key director = value[1] if director not in director_sorted: director_sorted[director] = [[title, year]] else: director_sorted[director].append([title, year]) for director in sorted(director_sorted): print (str(director) + ":") movies = director_sorted[director] for movie in sorted(movies, key=lambda x: x[0]): print(" " + movie[0] + ", " + str(movie[1])) elif userChoice == "t": for key, value in sorted(movieCollectionDict.items(), key=lambda item: (item[0], item[1])): print(str(key) + ":") print(" " + str(value[1]) + ", " + str(value[0])) else: print("Invalid response")
Error:
As you can see I am having problems with the order that is printing and some returns please help
Choose an option: 2005: Munich, Steven Spielberg 2006: The Departed, Martin Scorsese The Prestige, Christopher Nolan Into the Wild, Sean Penn The Dark Knight, Christopher Nolan Mary and Max, Adam Elliot The King's Speech, Tom Hooper The Artist, Michel Hazanavicius 2007: 2008: 2009: 2010: 2011: Your output The Help, Tate Taylor 2012: 2013: 12 Years a Slave, Steve McQueen 2014Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started