On Mon, Oct 21, 2019 at 10:25:57AM -0500, Dan Sommers wrote:

> Iterables are ordered collections of values, and outside of
> specialized subclasses, we can't expect that adding the values
> is meaningful or even possible.

Correct. That's why lists, tuples, strings, bytes and even arrays all 
define addition as concatentation rather than element-by-element 
addition. We leave it to specialised libraries and data types, like 
numpy, to implement element-by-element addition.


> "Adding the values" is too
> specialized and not general enough for iterables.

Correct. That's why join is a specialised string method, rather than a 
method on more general lists.


> And yet the builtin function sum exists and works the way it
> does.

Yes, because sum is a specialised function whose job is to sum the 
values of an iterable. What did you think it was, if it wasn't a 
specialised "sum these values" function?


-- 
Steven
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/7KPNEF5UFT4S4ZQFX6PCCEYRXTPKB65T/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to