Thanks for all your replies. A lot of very strong answers :) 2009/3/26 Mensanator <mensana...@aol.com>: > What would you have to do to make this work? > >>>> x+x+x # expecting [3,6] > [2, 4, 1, 2]
What's happening is that the call to map() is returning a list object. So after it calculates the first "x+x", you are left with the equivalent of: [6, 6] + x Because the list object is on the left, it's __add__() function is called, which appends x to [6,6]. Instead, convert the list returned by map to a Vector before returning it. Like so: >>> class Vector(list): ... def __add__(self, other): ... return Vector(map(add, self, other)) ... >>> x = Vector([3,3]) >>> x+x+x [9, 9] >>> -- "Ray, when someone asks you if you're a god, you say YES!" -- http://mail.python.org/mailman/listinfo/python-list