'This next part is key'


#1




Traceback (most recent call last):
File "python", line 6, in
KeyError: (105, 106)


residents = {'Puffin' : 104, 'Sloth' : 105, 'Burmese Python' : 106}

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

print residents[105,106]


#3

Any idead why:

print residents['Sloth', 'Burmese Python'], doesn't work?


#4

you have a dictionary, which has 3 keys:

Puffin, Sloth and Burmese Python

you can use this keys to get the values, like you did here:`

print residents['Puffin']

there is no other way, you have to use the keys to get the values.

@sportingcp because there is no (Sloth', 'Burmese Python') key. The only other option you have is a loop


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.