[Python-Dev] list comprehensions again...

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


Thomas Wouters wrote:
> 
> .... They provide an easier way to create a list, but they don't
> eradicate the need for map, reduce or filter, because there is no way to
> comprehend an already created list.

What do you mean? I think I see examples of list comprehensions working
on existing lists on this page:

http://www.cosc.canterbury.ac.nz/~greg/python/listcomp/

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

Reduce is somewhat of a different beast...

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