[Python-3000] join vs. add [was: Python 3000 Status Update (Long!)]

Joel Bender jjb5 at cornell.edu
Thu Jun 21 21:59:03 CEST 2007


> My preference would be to limit sum() to value addition only, and never do 
> concatenation.

I would be happy with that, provided there was join function and operator:

     >>> join = lambda x: reduce(lambda y, z: y.__join__(z), x)

I think this is clearer than sum():

     >>> join(['a', 'b', 'c'])
     'abc'

It wouldn't interfere with ''.join(), and ''.__add__() could be 
redirected to ''.__join__().

> For all non numeric types it would generate an exception.

How about generating an exception where __add__ isn't defined, so it 
would work on MyFunkyVector type.  I could join my vectors together as 
well, since in MyNonEucledeanSpace, it doesn't mean the same thing as "add".


Joel



More information about the Python-3000 mailing list