[Python-Dev] join() et al.

Skip Montanaro skip@mojam.com (Skip Montanaro)
Tue, 16 May 2000 09:52:59 -0500 (CDT)


    >> Alternatively, there has been talk about moving join() into the
    >> built-ins, but I'm not sure if the semantics of tha have been nailed
    >> down.

    Marc> This is probably the way to go. Semantics should probably
    Marc> be:

    Marc> 	join(seq,sep) := reduce(lambda x,y: x + sep + y, seq)

    Marc> and should work with any type providing addition or concat slot
    Marc> methods.

Of course, while it will always yield what you ask for, it might not always
yield what you expect:

    >>> seq = [1,2,3]
    >>> sep = 5
    >>> reduce(lambda x,y: x + sep + y, seq)
    16

;-)

-- 
Skip Montanaro, skip@mojam.com, http://www.mojam.com/, http://www.musi-cal.com/
"We have become ... the stewards of life's continuity on earth.  We did not
ask for this role...  We may not be suited to it, but here we are."
- Stephen Jay Gould