Introducing Python to others
David C. Ullrich
dullrich at sprynet.com
Thu Apr 2 12:02:30 EDT 2009
In article <mailman.3007.1238515574.11746.python-list at python.org>,
"andrew cooke" <andrew at acooke.org> wrote:
> David C. Ullrich wrote:
> > In article <TM6dnZxRVIQ0QFbUnZ2dnUVZ_rmdnZ2d at pdx.net>,
> > Scott David Daniels <Scott.Daniels at Acm.Org> wrote:
[...]
> >>
> >> class Vector(list):
> >> def __add__(self, other):
> >> return type(self)(x + y for x, y in zip(self, other))
> >
> > Question: I would have thought it would be
> >
> > return type(self)([x + y for x, y in zip(self, other)])
> >
> > What's this thing that looks like a list comprehension but isn't?
>
> it's a generator expression.
> http://docs.python.org/3.0/reference/expressions.html#index-3735
Ah, thanks. I see "dict comprehensions" there too - keen.
Sometime I gotta get around to actually learning this 2.x
stuff. Thought I had an idea how 1.x worked...
> andrew
--
David C. Ullrich
More information about the Python-list
mailing list