[Tutor] Strange join syntax

Tom Jenkins tjenkins@devis.com
26 Apr 2002 15:09:33 -0400


On Fri, 2002-04-26 at 14:03, Scot Stevenson wrote:
> Hello Remco, 
> 
> While talking about list reverse, you gave an example that included
> 
> > drow = ''.join(wordlist)
> 
> I tried this construction myself, and I see that it works, but I'm not 
> sure if I understand what is happening here. My docs [Python 2.1.1, yes 
> I'll be updating when I have time to install SuSE 8.0] say:

well this is a change that was added to 2.0+ that I frankly think
detracts from the readability of python (not that i can think of a
different way off the top of my head)

previous versions had a string module, so you would have to say:
  import string
  drow = string.join(wordlist, '')

starting in 2.0, you didn't need to import string, because strings now
had methods (basically the functions from the string module).  so by
saying
  drow = ''.join(wordlist)
you were saying "join the list wordlist using the string '' (empty
string) as the delimiter"


> 
> =================
> join(words[, sep]) 
> Concatenate a list or tuple of words with intervening occurrences of sep. 
> The default value for sep is a single space character. It is always true 
> that "string.join(string.split(s, sep), sep)" equals s. 
> =================
> 

or in version 2+ terms
sep.join(words)

ython.org/mailman/listinfo/tutor
-- 

Tom Jenkins
Development InfoStructure
http://www.devis.com