Dec-12-2018, 12:13 AM
Hello all!!
I am currently working on a homework assignment where I need to get information from a dictionary based off of a list. Example:
dict = {'title':[year, 'name'],....etc
list = ['name','name','name'].....etc
What I need to do is get the name from list to match the name in the dictionary and then print the values from the dictionary.
I am currently working on a homework assignment where I need to get information from a dictionary based off of a list. Example:
dict = {'title':[year, 'name'],....etc
list = ['name','name','name'].....etc
What I need to do is get the name from list to match the name in the dictionary and then print the values from the dictionary.
movies = {"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 Help": [2011, "Tate Taylor"], "The Artist": [2011, "Michel Hazanavicius"], "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"]} options = input('Choose a sort option: \n') director_list = [] if options == 'd': for key in movies: i = 1 while i < len(movies[key]): director_list.append(movies[key][i]) i += 2 set_director = sorted(set(director_list)) for key in set_director: print('%s:\n' % key) i = 0 for key, value in sorted(movies.items(), key=lambda item: (item[0], item[1])): i = 1 while i < len(movies[key]): print("\t" + key + ',',movies[key][0]) i += 2