coverting list back to string

scn regnivon at netscape.net
Tue Apr 22 09:37:56 EDT 2003


Erik.  This worked and thank you.  However, the lines of text are all
one continuous string instead of line-by-line.  I put an extra space
between ' '. join(remove) and was able to separate the list elements
with a space between each element.  Not sure on how to have each
string written as a separate line. My code probably needs a '\n'
somewhere and I'll play with it to find out.  Again, I've not
programmed much and appreciate your help. Scott

Erik Max Francis <max at alcyone.com> wrote in message news:<3EA44A5F.6ADA09B8 at alcyone.com>...
> scn wrote:
> 
> > my quest:  i know that output.write(remove) is not correct.  you
> > cannot use the 'write' method on a list.
> 
> Presumably you want to join the list back into a string, with something
> like:
> 
> 	' '.join(remove)
> 
> or in general
> 
> 	S.join(L)
> 
> where S is a delimiter string and L is a sequence.  Note that this may
> have an surprising effect since L.split() with no argument will split on
> _any_ block of whitespace, whereas ' '.join(L) will only join the parts
> back with a single space:
> 
> >>> L = 'this has  a   lot    of    spaces'.split()
> >>> ' '.join(L)
> 'this has a lot of spaces'
> 
> This may not bother you, but I thought I'd point it out as a clear
> difference.




More information about the Python-list mailing list