On 3/24/07, Steven H. Rogers <[EMAIL PROTECTED]> wrote:
> Anne Archibald wrote:
> >
> > P.S. reduce isn't even a numpy thing, it's one of python's
> > much-neglected lispy functions.
> >
>
> It looks like reduce(), map(), and filter() are going away for Python
> 3.0 since GvR believes that they are redundant and list comprehensions
> and generator expressions are more readable alternatives.  lambda was on
> the block as well, but will be retained.

Are you sure reduce is on the chopping block?  The PEP for generator
expressions doesn't say anything about reduce becoming redundant.
           http://www.python.org/dev/peps/pep-0289/
They give the example of
  reduce(lambda s, a: s + a.myattr, data, 0)
becoming
  sum(a[3] for a in data)

but that does nothing to address how functions like sum themselves
should be written. For a general binary operator, the equivalent of
"sum" can be conveniently expressed as a reduce operation.

As far as I can tell Python has no "prod" function.  So if one just
changes the example to
  reduce(lambda s, a: s * a.myattr, data, 1)
How does one write that in a simplified way using generator
expressions without calling on reduce?

--bb
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to