Dictionary

Serge Beaumont serge at sergebeaumont.com
Tue Aug 8 07:31:50 EDT 2000


I tried it in the interactove window to be sure:

i did this:

tup = ('A', 'B')
dict = {'A': 100}

dict[tup[0]]
100

So it should work. The key error occurs when you try to find a key that
isn't there. So either tup[0] is not 'A', or dict does not have a 'A'
key or both. Remember that Python is case sensitive...

Serge.

Nicholas Routledge wrote:

> Hi all,
>
> i'm new to python. could anyone see what might cause this error?
>
> in a program i have a tuple called tup.  tup[0] is 'A'.
> i also have a dictionary called dict. dict looks like this,
>
> dict = {'A': 100}
>
> now in my program i try to access dict like this,
> dict[tup[0]]
>
> it gives me a key error.  any ideas?
>
> --
> cheers,
> nick




More information about the Python-list mailing list