Can dictionary values access their keys?
Matthew Thorley
ruach at chpc.utah.edu
Fri Apr 8 12:33:53 EDT 2005
Axel Straschil wrote:
>
> For unique values, I did something like that couple of weeks ago, the
> thing you would need is the getKey thing, it's fast, but needs much
> memory for big structures becouse I use two dicts.
Thanks for the tip, I may give that a try. I'll be interested to see
what kind of speed penalty I pay. The data I am using has multiples
dictionaries with maybe a thousand entries each. But each entry is an
object containing a history of data with perhaps hundreds or even
thousands more entries. So we're talking about maybe a million+ total
nested key:values. I don't know if that counts as large or not. I can't
even guess how much k memory that is.
I must say I am *very* suprised that python does not have a way to look
up what key is pointing to a given object--without scanning the whole
list that is. Is that what list.index() does under-the-hood? I mean is
list.index(y) just the same as
itemnum = 0
for item in list:
if y == item:
return itemnum
else:
itemnum = itemnum+1
I think I am going to have to reevaluate my system design... grrr.
thanks
--
Matthew
More information about the Python-list
mailing list