split

David Wilson dw at botanicus.net
Fri Jun 11 18:14:38 CEST 2004


On Sat, Jun 12, 2004 at 08:40:44PM +0530, km wrote:

> i have a string like this 
> s = "znfciuheiahkcjnksdhuicvh"
> how to cut it into individual characrers and create an array out of it ? 
> i tried s.split()
> but it doesnt work

split() splits on a text delimiter - or if no argument is given, it
splits on whitespace. Try this instead, to get a list of the characters
in the string:

    chars = [ x for x in s ]

However, if you only need to read the individual characters, you can
directly index the string, eg:

    s[0]

Would evaluate to 'z'.


David.

-- 
"The significant problems we face cannot be solved at the same level of
thinking we were at when we created them."
    -- Albert Einstein




More information about the Python-list mailing list