[Python-Dev] list comprehensions again...

Paul Prescod paul@prescod.net
Tue, 11 Jul 2000 17:48:05 -0500


Greg Stein wrote:
> 
> Looks like all of us scrappy long-hairs are in this together. :-)
> 
> As I posted in another note: this stuff introduces too much confusion and
> unknowns, for a small benefit. Create parallel() or product() or whatever to
> munge the lists. Not new syntax.

Parallel iteration and list comprehensions are separate. I do prefer a
parallel() (merge?) builtin to the semicolon syntax, myself. You could
even define xparallel which is the lazy version (as in xrange).

There's no way you are going to invent functions that do everything that
list comprehensions do, however. And compared to map and filter, list
comprehensions are positively crystal clear. Would it help to think of
list comprehensions not so much as a vote for a new idea as a vote
AGAINST lambda, map and filter?

numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
mult3 = [3 * x for x in numbers]
evens = [x for x in numbers if x % 2 == 0]

numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
mult3 = map( lambda x: 3 * x, numbers)
evens = filter( lambda x: x%2==0, numbers)

-- 
 Paul Prescod - Not encumbered by corporate consensus
Simplicity does not precede complexity, but follows it. 
	- http://www.cs.yale.edu/~perlis-alan/quotes.html