split

Gandalf gandalf at geochemsource.com
Fri Jun 11 07:46:14 EDT 2004


This way:

 >>> s = 'some string'
 >>> l = []
 >>> for c in s:
...     l.append(c)
...
 >>> l
['s', 'o', 'm', 'e', ' ', 's', 't', 'r', 'i', 'n', 'g']
 >>>

However, in most cases, you do not need this. Please note that strings 
are seuqences. You can do these:

s[2]
s[1:3]
s[-4]

e.g. almost anything that you could do with a list.

Best,

   G

km wrote:

> hi all,
>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
>regards,
>KM
>
>
>
>  
>





More information about the Python-list mailing list