Storing 'unhashable' types in dictionaries by address
Ed Avis
ed at membled.com
Wed May 28 14:43:03 EDT 2003
aahz at pythoncraft.com (Aahz) writes:
>>I would like to store some 'extra' information associated with some
>>lists, but do so outside the lists themselves.
>Why not use a class?
> flavor1 = FlavorList(['strawberry'], 'yum')
In this case there were a couple of reasons. Firstly, the list of
values came from a library, which doesn't want to be bothered with
application-specific things like the 'yum' information. Its job is
just to return a list or something equally simple.
Given that, I could take the list returned from the library and wrap
it in my own class object. But I thought it would be clearer in this
case to store the 'annotations' separately from the class itself. I
like to debug by printing out data structures with PrettyPrinter, and
a list is easier to print out and view than a class which has a list
and several other random things (perhaps themselves data structures)
next to it.
--
Ed Avis <ed at membled.com>
More information about the Python-list
mailing list