Dictionary

Thomas Wouters thomas at xs4all.net
Tue Aug 8 08:50:10 EDT 2000


On Tue, Aug 08, 2000 at 08:03:23PM +1000, Nicholas Routledge wrote:

> 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?

Your 'tup' tuple apparently didn't contain 'A' as its first element, or it
wouldn't do that:

>>> tup = ('A', 'B', 'C')
>>> dict = {'A': 100}
>>> dict[tup[0]]
100

Are you certain 'tup' is a tuple ? Are you certain its first element is
indeed 'A' ? Try showing us the code, as small as possible, that displays
the problem.

-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!




More information about the Python-list mailing list