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/2005-March/052273.html below:

[Python-Dev] python-dev Summary for 2005-03-01 through 2005-03-15 [draft]

[Python-Dev] python-dev Summary for 2005-03-01 through 2005-03-15 [draft] [Python-Dev] python-dev Summary for 2005-03-01 through 2005-03-15 [draft]Nick Coghlan ncoghlan at iinet.net.au
Fri Mar 18 11:57:59 CET 2005
> -------------------------
> sum() semantics discussed
> -------------------------
> Guido's blog entry on `the fate of reduce() in Python 3000`_ (which 
> reiterated Guido's plan to cut map(), reduce(), filter() and lambdas 
> (what about zip()?) caused a huge discussion on whether sum() worked the 
> best way possible.  As it stands now, sum() only accepts a sequence of 
> numbers and its optional second argument works as an initial value to 
> build off of.

That last sentence isn't quite true. With an appropriate second argument, sum 
can be used to sum any sequence (even one containing strings):

Py> class additive_identity(object):
...   def __add__(self, other):
...     return other
...
Py> sum(["a"] * 5, additive_identity())
'aaaaa'

This is fairly abusive of sum, though :)

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at email.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.skystorm.net
More information about the Python-Dev mailing list

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