Generic singleton

Arnaud Delobelle arnodel at googlemail.com
Wed Mar 3 14:44:41 EST 2010


mk <mrkafk at gmail.com> writes:
[...]
> hashable
> ..
>     All of Python’s immutable built-in objects are hashable, while no
> mutable containers (such as lists or dictionaries) are.
>
> Well ok, hashable they're not; but apparently at least dict and list
> have id()?

lists and dicts are not hashable, but their types are:

>>> hash(dict)
4296155808
>>> hash(list)
4296151808

So just use the type as the key to the dictionary you maintain in your
singleton.  But the question is what you use your singleton for.

-- 
Arnaud



More information about the Python-list mailing list