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

Discussion in 'Python' started by Mark Niemczyk, May 13, 2011.

  1. 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
    Mark Niemczyk, May 13, 2011
    #1
    1. Advertising

  2. Mark Niemczyk

    noydb Guest

    On May 13, 1:25 pm, Mark Niemczyk <> 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!
    noydb, May 13, 2011
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Klaus Neuner
    Replies:
    7
    Views:
    475
    Klaus Neuner
    Jul 26, 2004
  2. Replies:
    2
    Views:
    281
    bruno modulix
    May 6, 2005
  3. Poppy
    Replies:
    1
    Views:
    384
    Poppy
    May 30, 2008
  4. noydb
    Replies:
    6
    Views:
    359
    Terry Reedy
    May 14, 2011
  5. Replies:
    2
    Views:
    170
    John Bokma
    Aug 30, 2013
Loading...

Share This Page