Man, this is not my week! Another bug in my posted code! The posted
version of SymmetricDict fails when adding an entry in which the key
equals the value. First bug is in __setitem__ in which the insertion
is done twice, which is wasteful but benign. The second bug is in
__delitem__, which
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
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.
A Python dictionary needs a unique key, so a pair
of keys is still one unique key, but probably it is some
kind
Just an example of dictionary object in python.
PythonWin 2.4.1 (#65, Mar 30 2005, 09:33:37) [MSC v.1310 32 bit
(Intel)] on win32.
Portions Copyright 1994-2004 Mark Hammond ([EMAIL PROTECTED]) -
see 'Help/About PythonWin' for further copyright information.
d = {}
d[key1] = value1
d[key2] =
On Thursday 23 June 2005 02:40 pm, Florian Lindner wrote:
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
Hi All--
Terry Hancock wrote:
On Thursday 23 June 2005 02:40 pm, Florian Lindner wrote:
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
Ivan Van Laningham wrote:
Well, Florian said, using two different keys, both unique; if that is
true, then a single key maps to a single value vice versa.
Of course you are right. I got caught up in the problem I imagined (the
pair being unique).
... subclass dict and provide get/set that
No need to update __getitem__, since the modified __setitem__ drops in
the reverse values. But __delitem__ needs overriding, and some special
guard needs to be added to __setitem__ to prevent orphaning any old
value:key entries.
-- Paul
Here's one possible solution:
class SymmetricDict(dict):