10/14 "This Next Part is Key"


#1

Hey everybody, can anybody tell me why i can't print this code?

# Assigning a dictionary with three key-value pairs to residents:
residents = {'Puffin' : 104, 'Sloth' : 105, 'Burmese Python' : 106}

print residents['Puffin'] # Prints Puffin's room number

# Your code here!
print residents['Sloth', 'Burmese Python']

--------------------------------------------------------------------------

BUT, this bottom code works

# Assigning a dictionary with three key-value pairs to residents:
residents = {'Puffin' : 104, 'Sloth' : 105, 'Burmese Python' : 106}

print residents['Puffin'] # Prints Puffin's room number

# Your code here!
print residents['Sloth']
print residents['Burmese Python']

can you not print 2 dictionary values at a time?


#2

You can, try this instead;

print residents['Sloth'], residents['Burmese Python']

#3

Thank you for the reply! This worked, although I was thinking there was a way around typing "residents" twice, seems a little redundant but maybe there is no way around this. .


#4

i don't think so, you could take a look here: Python Docs about Dictionairies

If the thread is solved, please click solved and like! Thanks in advance :smile: