Dictionary
Alex Martelli
alex at magenta.com
Tue Aug 8 06:48:04 EDT 2000
"Nicholas Routledge" <n.routledge at bigpond.com> wrote in message
news:ERQj5.26704$c5.75550 at newsfeeds.bigpond.com...
> 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?
Sorry, can't reproduce your error:
>>> tup=('A','B')
>>> dict={'A':100}
>>> dict[tup[0]]
100
>>>
Clearly, if you get a key error then either dict or tup is
not at that point what you expect them to be. So, print
them out right before the point where it fails (with a
print statement, or via debugger, or whatever) and see.
Alex
More information about the Python-list
mailing list