Opposite of split

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sun Aug 15 19:33:10 EDT 2010


On Sun, 15 Aug 2010 12:10:10 -0700, Steven Howe wrote:

>> Strings have a join method for this:
>>     '\t'.join(someList)
>>
>> Gary Herron
> or maybe:
> ----------------------------------------- 
> res = ""
> for item in myList:
>      res = "%s\t%s" %  ( res, item )


Under what possible circumstances would you prefer this code to the built-
in str.join method?

Particularly since the code isn't even correct, as it adds a spurious tab 
character at the beginning of the result string. 

(By the way, your solution, to call res.strip(), is incorrect, as it 
removes too much.)


-- 
Steven



More information about the Python-list mailing list