[Python-3000] what do I use in place of reduce?
"Martin v. Löwis"
martin at v.loewis.de
Thu Apr 24 20:23:35 CEST 2008
> On Wed, Apr 23, 2008 at 10:40 PM, "Martin v. Löwis" <martin at v.loewis.de
> <mailto:martin at v.loewis.de>> wrote:
>
> py> time % 60, time//60%60, time//3600%24, time//(3600*24)
> (28, 7, 0, 22)
>
> the 3600 and 3600*24 was what I was trying to avoid.
This is getting off-topic, so you don't need to answer; I still ask:
Why???
It's still *shorter* than your reduce version, and much much much
more legible. Readability counts.
> I like the divmod
> solution. You can also use it in the reduce :)
> reduce(lambda a, b: divmod(a[0], b) + a[1:], [(t,), 60, 60, 24])[::-1]
Even after knowing what this does, I still cannot easily understand
how it does that. I think having reduce produce a growing value, and
passing it an inhomogeneous list, is just deep abuse.
In any case, writing multiple lines is good, writing a single line only
is bad.
Regards,
Martin
More information about the Python-3000
mailing list