[Tutor] reduce with comprehension
Kent Johnson
kent37 at tds.net
Mon Nov 21 11:55:25 CET 2005
János Juhász wrote:
> Hi,
>
> I can't imagine how this could be made with list comprehension.
>
>>>>import operator
>>>>a = (([1],[2],[3,31,32],[4]), ([5],[6],[7, 71, 72]), ([8],[9]))
>>>>reduce(operator.add, a) # it makes a long list now
>
> Is it possible to substitute reduce with comprehension anyway ?
Not that I know. Why are you trying to eliminate reduce()? If it is for compatibility with Python 3.0, PEP 3000 recommends replacing reduce() with an explicit loop.
http://www.python.org/peps/pep-3000.html#built-in-namespace
Kent
--
http://www.kentsjohnson.com
More information about the Tutor
mailing list