[Tutor] Creating a list from a comma-seperated string.

Lloyd Hugh Allen lha2@columbia.edu
Tue, 19 Mar 2002 17:38:22 -0500


Deirdre Saoirse wrote:
> 
> On Tue, 19 Mar 2002 Doug.Shawhan@gecits.ge.com wrote:
> 
> > I know this is probably very simple.
> >
> > I have strings of comma-seperated text that I want to split into lists.
> >
> > split() of course, seperates every letter. How do I tell split() to do it's
> > business at the commas?
> 
> split takes an optional second argument:
> 
> no_commas_please = string.split(string_with_commas, ',')

Or, since There's More Than One Way To Do It (oops, wrong language)
(hey, wait, I don't even know that language), I personally find

string_with_commas.split(',')

more readable. Even if its inverse is

','.join(list_of_strings)