[Python-3000] what do I use in place of reduce?
Guido van Rossum
guido at python.org
Thu Apr 24 03:47:20 CEST 2008
On Wed, Apr 23, 2008 at 1:56 PM, Nicholas T <ntung at ntung.com> wrote:
> It's obvious how to use LC's to replace map and filter, but what about
> reduce? It is one of my favorite functions.
>
> >>> time=1901248
> >>> reduce(lambda a, b: a[:-1] + [a[-1]%b, math.floor(a[-1]/b)], [[time],
> 60, 60, 24])
> [28, 7.0, 0.0, 22.0] # secs, mins, hrs, days
I recommend learning how to use a good old for-loop. That example is
as cryptic as can be. It's also inefficient due to calling a function
for each iteration.
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-3000
mailing list