Dictionaries with invalid key?

Fredrik Lundh fredrik at pythonware.com
Mon Sep 6 10:34:20 EDT 1999


Gerhard W. Gruber <g.gruber at xsoft.co.at> wrote:
> Usually a dictionary conists of a key and a value. I thought that keys
> are strings. Now I wrote some code that managed to create a key that is
> a number instead of a string. Is this a bug or is this ok?

reading the documentation may help:

http://www.python.org/doc/current/lib/typesmapping.html

    There is currently only one standard mapping type,
    the dictionary. A dictionary's keys are almost arbi-
    trary values. The only types of values not acceptable
    as keys are values containing lists or dictionaries or
    other mutable types that are compared by value
    rather than by object identity.

The tutorial also discusses dictionaries (section 5.4).

</F>





More information about the Python-list mailing list