Why " ".some_string is often used ?

Peter Hansen peter at engcorp.com
Thu Jan 8 10:02:02 EST 2004


John Roth wrote:
> 
> And I agree, it's not entirely obvious why it's a string
> method rather than a list method, since it operates on
> a list, not on a string. The only explanation that makes
> sense is that, as a list method, it would fail if the list
> contained something other than a string. That's still
> not very friendly, though.

One could about as easily argue (and I believe several have done
this quite well in the past, better than I anyway) that you are
actually operating on the *string*, not the list.  You are in
effect asking the string to act as a joiner for the elements in the
list, not asking the list to join itself using the specified
string.

At least, if you look at it that way, it might be easier to swallow.

-Peter



More information about the Python-list mailing list