[Python-Dev] Re: accumulator display syntax

Guido van Rossum guido at python.org
Mon Oct 20 14:15:22 EDT 2003


> Most of us seem to agree that having list comprehensions 
> available as a replacement for map() and filter() is a good
> thing. But what about reduce()? Are there equally strong
> reasons for wanting an alternative to that, too? If not,
> why not?

If anything, the desire there is *more* pressing.  Except for
operator.add, expressions involving reduce() are notoriously hard to
understand (except to experienced APL or Scheme hackers :-).

Things like sum, max, average etc. are expressed very elegantly with
iterator comprehensions.

I think the question is more one of frequency of use.  List comps have
nothing over e.g.

  result = []
  for x in S:
      result.append(x**2)

except compactness of exprssion.  How frequent is

  result = 0.0
  for x in S:
      result += x**2

???

(I've already said my -1 about your 'sum of ...' proposal.)

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list