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

noydb jenn.duerr at gmail.com
Fri May 13 13:31:26 EDT 2011


On May 13, 1:25 pm, Mark Niemczyk <praham... at gmail.com> wrote:
> There are a series of built-in methods for string objects; including the split method which will accomplish exactly the result you are looking for.
>
> >>> x = "red;blue;green;yellow"
> >>> color_list = x.split(';')
> >>> color_list
>
> ['red', 'blue', 'green', 'yellow']
>
>
>
> Here is the link to a discussion of the build-in str methods (3.2), but this documentation exists for prior versions of Python as well.
>
>      http://docs.python.org/py3k/library/stdtypes.html#str.split
>
> Good luck,
>
> Mark Niemczyk

Haha!  This is why I ask, because my code is pretty laughable and
elementary!  I'm learning...
Thanks Mark!



More information about the Python-list mailing list