[Python-Dev] List comprehensions
M.-A. Lemburg
mal@lemburg.com
Thu, 13 Jul 2000 20:22:24 +0200
Paul Prescod wrote:
>
> Skip Montanaro wrote:
> >
> > Paul> [for x: if y(x): for z: (x,y,z)]
> >
> > Agreed, however, your use of colons connotes the following to me
> >
> > l = []
> > for x in something:
> > if y(x):
> > for z in something_else:
> > l.append((x,y,z))
> > return l
>
> Yes, that's right. I forgot the "in something" and "in something_else"
> parts but your interpretation was still correct (a fault tolerant
> notation!!).
>
> [for x in something: if y(x): for z in something_else: (x,y,z)]
Is it really necessary to have all the "code" inside the square
brackets ?
I always thought of list comprehension as a fast way to
just throw together a list, not as a way to "program" the
list contents. IMHO, that should be done using explicit
statements in the way Skip describes above.
I would be completely satisfied with e.g. [0..10], [0..10:2]
and [10..0].
--
Marc-Andre Lemburg
______________________________________________________________________
Business: http://www.lemburg.com/
Python Pages: http://www.lemburg.com/python/