How best to convert a string "list" to a python list

Redcat redcat at catfolks.net
Fri May 13 15:26:40 EDT 2011


On Fri, 13 May 2011 10:15:29 -0700, noydb wrote:

> I want some code to take the items in a semi-colon-delimted string
> "list" and places each in a python list.  I came up with below.  In the
> name of learning how to do things properly, do you experts have a better
> way of doing it?

How about the below?

dan at dan:~/development$ python
Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> x = "cyan;magenta;yellow;black"
>>> xList = x.split(';')
>>> xList
['cyan', 'magenta', 'yellow', 'black']
>>>




More information about the Python-list mailing list