"Jia Lu" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I see dict type can do 1-to-1 pattern, But is there any method to do
> 1-to-many, many-to-1 and many-to-many pattern ?
Dict objects can do many-to-1 relationships.
Dict[Key1] = Obj
Dict[Key2] = Obj
Dict[Key3] = Obj
1-to-many relationships are more tricky and not something built-in to
dictionaries. You can make each value in the dictionary a list of
associated values:
Dict[Key] = [Obj1, Obj2, Obj3]
You can even subclass dict to give it the members you like, for example:
class OneToMany(dict):
def Add(self, Index, Value):
V = self.get(Index, [])
V.append(Value)
self[Index] = V
--
http://mail.python.org/mailman/listinfo/python-list