Introducing Python to others

mmanns at gmx.net mmanns at gmx.net
Thu Mar 26 14:19:07 EDT 2009


On Thu, 26 Mar 2009 12:42:01 -0400 (CLT)
"andrew cooke" <andrew at acooke.org> wrote:

> that's cute, but if you show them 2.6 or 3 it's even cuter:
> 
> >>> from operator import add
> >>> class Vector(list):
> ...   def __add__(self, other):
> ...     return map(add, self, other)
> ...
> >>> x = Vector([1,2])
> >>> x+x
> [2, 4]

Works for me in 2.5.4 (Linux) :-)

Martin



More information about the Python-list mailing list