[Python-Dev] String methods... finally

David Ascher da at ski.org
Fri Jun 11 07:09:46 CEST 1999


On Fri, 11 Jun 1999, Skip Montanaro wrote:

> It occurred to me just a few minutes after sending my previous message that
> it might make sense to make string.join a method for lists and tuples.
> They'd obviously have to make the same type checks that string.join does.

as in:

   >>> ['spam!', 'eggs!'].join()
   'spam! eggs!'

?  

I like the notion, but I think it would naturally migrate towards
genericity, at which point it might be called "reduce", so that:

   >>> ['spam!', 'eggs!'].reduce()
   'spam!eggs!'
   >>> ['spam!', 'eggs!'].reduce(' ')
   'spam! eggs!'
   >>> [1,2,3].reduce()
   6  # 1 + 2 + 3
   >>> [1,2,3].reduce(10)
   26 # 1 + 10 + 2 + 10 + 3

note that string.join(foo) == foo.reduce(' ')
     and  string.join(foo, '') == foo.reduce()

--david






More information about the Python-Dev mailing list