[Python-3000] Python 3000 Status Update (Long!)

Collin Winter collinw at gmail.com
Tue Jun 19 18:46:08 CEST 2007


On 6/19/07, Bill Janssen <janssen at parc.com> wrote:
> > > written using list-comprehensions.. so why  _reduce_?
> >
> > Don't worry, it wasn't complete removed. Reduce was moved to functools
>
> Though, really, same question!  There are functional equivalents (list
> comprehensions) for "map" and "filter", but not for "reduce".

There is a range of list comprehensions that are more
readably/concisely expressed as calls to map or filter:

[f(x) for x in y] -> map(f, y)
[x for x in y if f(x)] -> filter(f, y)

Turning a for loop into the equivalent reduce() may be more concise,
but as Guido has remarked before, someone new to your code generally
has to break out pen and paper to figure out what's going on.

> Shouldn't "reduce" stay in the 'built-in' space, while the other two
> move to "functools"?  Or move them all to "functools"?  Bizarre
> recombination, IMO.

Arguing from the standpoint of purity, that, "these functions are
builtins, why not this other one" isn't going to get you very far.
Another data point to consider is that map and filter are used far,
far more often than reduce (100000 and 62000 usages to 10000, says
Google Code Search), so there's more resistance to moving them.

Collin Winter


More information about the Python-3000 mailing list