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. Advertisements

  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. Advertisements

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. Andrew Banks

    Convert string to a string array

    Andrew Banks, Apr 19, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    58,773
    Andrew Banks
    Apr 19, 2004
  2. =?Utf-8?B?TWlrZSBNb29yZQ==?=

    Connection String object Convert to String Variable Type

    =?Utf-8?B?TWlrZSBNb29yZQ==?=, Oct 26, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,198
    Norman Yuan
    Oct 26, 2004
  3. rockdale

    Convert formatted string to string?

    rockdale, Apr 11, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    551
    rockdale
    Apr 12, 2006
  4. Klaus Neuner
    Replies:
    7
    Views:
    809
    Klaus Neuner
    Jul 26, 2004
  5. Replies:
    2
    Views:
    342
    bruno modulix
    May 6, 2005
  6. Poppy
    Replies:
    1
    Views:
    527
    Poppy
    May 30, 2008
  7. noydb
    Replies:
    6
    Views:
    542
    Terry Reedy
    May 14, 2011
  8. Replies:
    2
    Views:
    347
    John Bokma
    Aug 30, 2013
Loading...