'This next part is key'


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]


Any idead why:

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


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


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