How to parse a string completely into a list
I want to take a long alpha-numeric string with \n and white-space and place ALL elements of the string (even individual parts of a long white-space) into separate list elements. The most common way I've seen this performed is with the split() function, however I don't believe that it has the power to do what I am looking for. Any suggestions? thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: How to parse a string completely into a list
On Sep 24, 9:44 pm, "Chris Rebert" <[EMAIL PROTECTED]> wrote: > On Wed, Sep 24, 2008 at 8:30 PM, <[EMAIL PROTECTED]> wrote: > > I want to take a long alpha-numeric string with \n and white-space and > > place ALL elements of the string (even individual parts of a long > > white-space) into separate list elements. The most common way I've > > seen this performed is with the split() function, however I don't > > believe that it has the power to do what I am looking for. > > Any suggestions? > > thanks > > -- > >http://mail.python.org/mailman/listinfo/python-list > > Could you please define exactly what you mean by "elements" of a string? > > If you mean characters, then just use list():>>> list(" \n \t abc") > > [' ', ' ', '\n', ' ', '\t', ' ', 'a', 'b', 'c'] > > Regards, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com Worked like a charm. kudos! -- http://mail.python.org/mailman/listinfo/python-list
Re: How to parse a string completely into a list
On Sep 24, 10:12 pm, Matt Nordhoff <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > On Sep 24, 9:44 pm, "Chris Rebert" <[EMAIL PROTECTED]> wrote: > >> On Wed, Sep 24, 2008 at 8:30 PM, <[EMAIL PROTECTED]> wrote: > >>> I want to take a long alpha-numeric string with \n and white-space and > >>> place ALL elements of the string (even individual parts of a long > >>> white-space) into separate list elements. The most common way I've > >>> seen this performed is with the split() function, however I don't > >>> believe that it has the power to do what I am looking for. > >>> Any suggestions? > >>> thanks > >> Could you please define exactly what you mean by "elements" of a string? > > >> If you mean characters, then just use list():>>> list(" \n \t abc") > > >> [' ', ' ', '\n', ' ', '\t', ' ', 'a', 'b', 'c'] > > >> Regards, > >> Chris > > > Worked like a charm. > > kudos! > > Why do you need to convert it to a list? Strings are sequences, so you > can do things like slice them or iterate through them by character: > > >>> for character in "foo": > > ... print character > ... > f > o > o > > -- The string draws a map that I then want to be able to traverse through. If I can count through the individual characters of a list I can create an x-y coordinate plane for navigation. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to parse a string completely into a list
On Sep 25, 1:51 am, Tino Wildenhain <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > On Sep 24, 10:12 pm, Matt Nordhoff <[EMAIL PROTECTED]> wrote: > >> [EMAIL PROTECTED] wrote: > >>> On Sep 24, 9:44 pm, "Chris Rebert" <[EMAIL PROTECTED]> wrote: > > Could you please define exactly what you mean by "elements" of a string? > If you mean characters, then just use list():>>> list(" \n \t abc") > [' ', ' ', '\n', ' ', '\t', ' ', 'a', 'b', 'c'] > Regards, > Chris > >>> Worked like a charm. > >>> kudos! > >> Why do you need to convert it to a list? Strings are sequences, so you > >> can do things like slice them or iterate through them by character: > > > for character in "foo": > >> ... print character > >> ... > >> f > >> o > >> o > > >> -- > > > The string draws a map that I then want to be able to traverse > > through. If I can count through the individual characters of a list I > > can create an x-y coordinate plane for navigation. > > You can 'count' (whatever that means) equally in strings as you do in > lists. As said above, they behave exactly the same. Just strings > are imutable - e.g. you can't change individual parts of them. > > Tino > > > -- > >http://mail.python.org/mailman/listinfo/python-list > > smime.p7s > 4KViewDownload Ahh, but I forgot to mention that I have to mark the path I took in the string. So using list() and then join() are my best options. -- http://mail.python.org/mailman/listinfo/python-list