string.join() syntax quirky?

Bjorn Pettersen BPettersen at NAREX.com
Mon Nov 26 19:36:07 CET 2001


> From: Russell E. Owen [mailto:owen at astrono.junkwashington.emu] 
> 
> In article <3BFD49D8.F7A4C6CC at earthlink.net>,
>  Erik Johnson <ejohnso9 at earthlink.net> wrote:
> 
> >... I have a list of single character strings. A couple of 
> people were 
> >kind enough to clue me in to the best way to turn this back to a 
> >string:
> >
> >s = "".join(l)
> >
> >    This works fine, but it seems syntactically backwards to me:
> >
> ># s = l.join("")
> >
> >makes much more sense to me. The thingy I want to do 
> something to is my 
> >list. I am just trying to learn Python, so no doubt there 
> will be some 
> >Python things I will just have to get used to, but is there 
> a logical 
> >reason why it was implemented as a string method rather than a list 
> >method? Does it seem backwards to you or does it make 
> intuitive sense 
> >to you? Comments? (other than of the "it's moot" flavor)
> 
> I would also prefer having join be a list method, but there are good 
> reasons for the current design.
> 
> One way to look at it is that the various collection classes do NOT 
> inherit from a single base class (which would be a logical place to 
> define a join method). Hence to have all kinds of collections 
> learn to 
> "join" requires a lot of repeat coding. Making join a string method 
> solves this problem.

So instead of doing what's right we're doing what's convenient? Doesn't
sound very Pythonic <wink>

-- bjorn




More information about the Python-list mailing list