Guys I'm looking for a clean way of splitting a string into a list:

I have this:

myString = 'blue, red, pink, purple'

and I want this:

myString = ['blue', 'red', 'pink', 'purple']

How do I do that?

Recommended Answers

It is explained in [url=http://www.freenetpages.co.uk/hp/alan.gauld/tuttext.htm]this tutorial[/url]. Also a web search for "python string split" will turn up more examples. You can use a split and specify the character, or replace and then split() with the default=space(s).

Jump to Post

All 4 Replies

It is explained in this tutorial. Also a web search for "python string split" will turn up more examples. You can use a split and specify the character, or replace and then split() with the default=space(s).

Thanks guys I got it:

myString.split(', ')