Data Structure Question
Alex
new_name at mit.edu
Sun Jun 17 13:04:50 EDT 2001
If you're storing hashable objects in your dictionary, you could try
something like this:
from UserDict import UserDict
class MultiDict(UserDict):
def __setitem__(self, key, value):
l = self.data[key] = self.data.get(key, {})
l[value] = None
d = MultiDict()
d['key'] = 'value1'
d['key'] = 'value2'
d['key'] = 'value1'
assert d['key'] == {'value1': None, 'value2': None}
HTH
Alex.
More information about the Python-list
mailing list