Pre-PEP: __hashable__
Lulu of the Lotus-Eaters
mertz at gnosis.cx
Tue Dec 10 23:45:34 EST 2002
Chad Netzer <cnetzer at mail.arc.nasa.gov> wrote:
|> key = tuple(dct.items())
|Not all tuples are hashable.
True enough. I was trying to give you what you asked for, but no more
(i.e. an immutable version of a dictionary). Inasmuch as you can spell
the identity function:
identity = lambda d: dict(tuple(d.items()))
I think this 'tuple(dct.items())' can very reasonably be called "an
immutable dictionary".
Of course, if you want something *hashable*, you could try:
key = cPickle.dumps(dct)
or,
key = pprint.pformat(dct)
It's not to hard to find identity functions involving those expressions
:-).
I-really-wanted-to-squeeze-in-the-word-idempotent-ly yours, Lulu...
--
mertz@ | The specter of free information is haunting the `Net! All the
gnosis | powers of IP- and crypto-tyranny have entered into an unholy
.cx | alliance...ideas have nothing to lose but their chains. Unite
| against "intellectual property" and anti-privacy regimes!
-------------------------------------------------------------------------
More information about the Python-list
mailing list