How best to convert a string "list" to a python list
Jerry Hill
malaclypse2 at gmail.com
Fri May 13 13:30:39 EDT 2011
On Fri, May 13, 2011 at 1:15 PM, noydb <jenn.duerr at gmail.com> 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?
Strings have a split method, which splits the string into a list based
on a delimiter, like this:
>>> x = "red;blue;green;yellow"
>>> color_list = x.split(";")
>>> print color_list
['red', 'blue', 'green', 'yellow']
That's how I'd do it.
--
Jerry
More information about the Python-list
mailing list