make a string a list

Tobiah toby at tobiah.org
Fri May 30 15:21:50 EDT 2008


>> or a string iterable ? How can I do that. I have lots of '\r\n'
>> characters in the string which I think can be easier if it were made
>> into a list and I can easily see if the required value (its a numeral)
>> is present in it or not after some position or after some characters'
>> position.

They already are.  They are quite like lists in many ways:

>>> s = 'abcdefg'
>>> for c in s: print c
...
a
b
c
d
e
f
g
>>> s[3]
'd'
>>> s = "foo\r\n"
>>> s.find("\r")
3
>>> s.replace("\r", "").replace("\n", "")
'foo'
>>>           

** Posted from http://www.teranews.com **



More information about the Python-list mailing list