[Python-3000] what do I use in place of reduce?
Nicholas T
ntung at ntung.com
Thu Apr 24 20:49:03 CEST 2008
On Thu, Apr 24, 2008 at 11:23 AM, "Martin v. Löwis" <martin at v.loewis.de>
wrote:
> This is getting off-topic, so you don't need to answer; I still ask:
> Why???
yes I know, apologies for not mailing the right list. I'll try to do so next
time. Dividing the previous result seems more logical: minutes = seconds/60,
hours=minutes/60, days=hours/24, not minutes=seconds/60, hours=seconds/3600,
days=seconds/86400. Also, if you do something like adding years, it's
simple--you just append to the list versus change the last thing to a modulo
and add another unit. If you add years, changing days to sidereal days
would also be easier with the list. Also, you don't have to check
multiplication, etc.
[in answer to your next question as well] The example was created to show
the ability to express things with reduce, not necessarily to quickly
calculate human readable time.
> 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.
I guess I am likely to agree: the function is not associative or
commutative, and unable to be parallelized--one of the reasons reduce was
created.
> In any case, writing multiple lines is good, writing a single line only
> is bad.
I don't agree. If it's code you want to write once and never look at again,
having it out of the way can be nice.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-3000/attachments/20080424/0ed35cd7/attachment.htm>
More information about the Python-3000
mailing list