Python Forum
Dictonary and list help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dictonary and list help
#1
Hey guys, I'm having tons of trouble getting this to work right. So for whatever reason, not all of the years are matching correctly and I cant figure out why. Some work fine, and others don't.

# Build a dictionary containing the specified movie collection
names = ['Munich, Steven Spielberg', 'The Prestige, Christopher Nolan' , 'The Departed, Martin Scorsese' ,
'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' , 'The Help, Tate Taylor' , 'Argo, Ben Affleck' , '12 Years a Slave, Steve McQueen' , 
'Birdman, Alejandro G. Inarritu' ,'Spotlight, Tom McCarthy' , 'The BFG, Steven Spielberg']
movies = {
2005 : names[0], 2006 : names[1:3], 2007 : names[3], 2008 : names[4], 2009 : names[5], 2010 : names[6], 
2011 : names[7:9], 2012 : names[9], 2013 : names[10], 2014 : names[11], 2015 : names[12], 2016 : names[13] 
}
    elif sel == 't':
        names.sort()
        for name in names:
            for key, value in movies.items():
                if name == 'The Departed' or name == 'The Prestige':
                    year = 2006
                elif name == 'The Help' or name == 'The Artist':
                    year = 2011
                elif name == value:
                    year = key
            temp = name.find(',')
            print(name[0:temp] + ':' )
            print('\t' + name[temp + 2:len(name)], year) 
            print('')
This is the output i'm getting
MENU
Sort by:
y - Year
d - Director
t - Movie title
q - Quit

Choose an option:
12 Years a Slave:
Steve McQueen 2013

Argo:
Ben Affleck 2012

Birdman:
Alejandro G. Inarritu 2014

Into the Wild:
Sean Penn 2007

Mary and Max:
Adam Elliot 2009

Munich:
Steven Spielberg 2005

Spotlight:
Tom McCarthy 2015

The Artist:
Michel Hazanavicius 2015

The BFG:
Steven Spielberg 2016

The Dark Knight:
Christopher Nolan 2008

The Departed:
Martin Scorsese 2008

The Help:
Tate Taylor 2008

The King's Speech:
Tom Hooper 2010

The Prestige:
Christopher Nolan 2010

Notice they years for 'The Artist', 'The Departed', 'The help', and 'the Prestige' is wrong. Im stuck! Any help would be appreciated!
Reply


Messages In This Thread
Dictonary and list help - by Btoulouse - Dec-09-2018, 08:44 PM
RE: Dictonary and list help - by Larz60+ - Dec-09-2018, 09:52 PM
RE: Dictonary and list help - by Btoulouse - Dec-09-2018, 10:01 PM
RE: Dictonary and list help - by Larz60+ - Dec-10-2018, 10:52 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Find a substring in a dictonary; value substring of key aapurdel 2 7,053 May-31-2019, 06:14 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020