> ------------------------- > 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
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