[Tutor] reduce with comprehension
kent37 at tds.net
Mon Nov 21 11:55:25 CET 2005
János Juhász wrote:
> I can't imagine how this could be made with list comprehension.
>>>>a = ((,,[3,31,32],), (,,[7, 71, 72]), (,))
>>>>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.
More information about the Tutor