Best way to hash a dictionary
sholden at holdenweb.com
Wed Feb 26 14:04:49 CET 2003
"Miki Tebeka" <tebeka at cs.bgu.ac.il> wrote ...
> I need to store dictionary as dictionary keys, and do it efficiently
> (which means using native types).
> Currently there are 3 ways I can think of:
> 1. Using a sorted tuple of dictionary items
> 2. Using a sorted string from the dictioary items
> 3. Using a string from the dicionary items (AFAIK this is a bug)
You will, I hope, pardon me saying that it sounds like rather important
design decisions have already been made. Perhaps if you were to explain
*why* you need to use dictionary equivalents as dictionary keys someone
might be able to spot a solution that doesn't require such contortions.
Please note, I'm not saying you definitely don't need to use dictionaries as
dictionary keys. Simply that it sounds like there may be a better way.
Finally: the reason you can't just use the dictionaries as keys, of course,
is that dictionaries are mutable. Does you design preclude any change to the
dicionaries after they become keys in the other dictionary? If so then you
may just be able to subclass the standard dict type. If not, then even your
current proposals will break, no?
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/pwp/
Register for PyCon now! http://www.python.org/pycon/reg.html
More information about the Python-list