key - key pairs

Scott David Daniels Scott.Daniels at Acm.Org
Thu Jun 23 16:28:02 EDT 2005


Florian Lindner wrote:
> Hello,
> is there in python a kind of dictionary that supports key - key pairs?
> I need a dictionary in which I can access a certain element using two
> different keys, both unique.
> 
> For example:
> 
> I've a dictionary with strings and times. Sometimes I have the string and I
> want to have the time, other time I've the time and I want the string. It
> is important that one of the keys supports the min/max builtin function.
> 
> Thanks,
> 
> Florian

As Claudio suggests, you probably want to make a class with (at least)
a pair of dictionaries.  Are the strings one-to-one with the times?

I am unsure of what you mean by "supports the min/max builtin function."
If all you mean is, "can I get the min and/or max of the keys (strings
or times), then a pair of dictionaries does it.  If you mean "finds
faster than linear," you need to say what operations are to be fastest,
and whether you mean worst case or amortized.  It is possible to make
the fast operations most combinations of:
     "find least",
     "find greatest",
     "remove least",
     "remove greatest",
     "find arbitrary",
     "remove arbitrary",
     "add entry"

Depending on your choice on costs, the data structure changes.

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list