python parsing question from a python newbie (though coding for 10 years)

Alex Martelli aleax at aleax.it
Mon Feb 3 16:30:07 EST 2003


Pat McGroin wrote:

> I need to take a string and parse\split\breakup the string into each
> seperate character into an array.  The only part I don't know is how
> to split into seperate chars, could someone please give me a quick 1
> line of code answer?

If you truly want an array, you'll need two lines of code, because
array is not a built-in, in Python -- you have to import it from
the Python standard library.  So:

>>> import array
>>> array.array('c','ciao')
array('c', 'ciao')
>>>

If, as is more likely, you want a list, not an array, then you
do indeed need just one line:

>>> list('ciao')
['c', 'i', 'a', 'o']
>>>


Alex





More information about the Python-list mailing list