reduce to be removed?

Fredrik Lundh fredrik at pythonware.com
Mon Nov 13 11:04:21 CET 2006


Steve Holden wrote:

> In actual fact when Alex Martelli introduced sum() he intended it to be 
> polymorphic over all the container types including strings. The check to 
> exclude the string case was added when it was determined that it was 
> terribly inefficient to concatenate strings that way. the same may well 
> apply to other sequences.

an important difference is that if you repeatedly copy a string object, 
you'll actually copy *all* data in the string over and over again.  when 
you copy a list, you only copy references to the objects in the list. 
the size of the data *in* the list doesn't matter.

> I suppose it's only a matter of time before someone wants to define 
> dict.__add__ ...

that's been proposed quite a few times, and always gets stuck when it's 
time to define the exact semantics for dealing with collisions.  there 
are simply too many ways to do it, and all of them are can be trivially 
and efficiently implemented in terms of copy/update or for-in (or, in 
quite a few cases, by using sets instead of dicts).

</F>




More information about the Python-list mailing list