A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2003-April/034801.html below:

summing a bunch of numbers (or "whatevers")

[Python-Dev] Fwd: summing a bunch of numbers (or "whatevers") [Python-Dev] Fwd: summing a bunch of numbers (or "whatevers")Jack Diederich jack@performancedrivers.com
Sun, 20 Apr 2003 10:29:04 -0400
On Sun, Apr 20, 2003 at 03:42:26AM -0500, Ka-Ping Yee wrote:
> New question: what is add([])?  If add() is really polymorphic, then
> this should probably raise an exception (just like min() and max() do).
> That would lead to idioms such as
> 
>     add(numberlist + [0])
> 
>     add(stringlist + [''])
> 
> I suppose those don't look too bad.  Nothing vastly better springs
> to mind.

For a large numberlist this is a problem, it causes a copy of the whole list.
Not to mention it looks like a perl coercion hack.  The third argument to 
reduce is there to avoid the hack.

so now we have

from newmodule import add
answer = add(numberlist, 0)

why don't we just write it as

from operator import add
answer = reduce(add, numberlist, 0)

-jack



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4