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

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(', ')
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.