Refeing to substring in list of strings

David Fisher python at rose164.wuh.wustl.edu
Sat Apr 8 06:33:26 EDT 2000


Referencing a substring works fine for me:

>>> ll = ['1234','asdf','qwer']
>>> for i in range(len(ll)):
    for j in range(len(ll[i]) - 1):
        print ll[i][j:j+2]


12
23
34
as
sd
df
qw
we
er
>>>

If you're trying to assign to the substring, like s[1:2] = 'e',  you can't,
strings are immutable.
dnf

----- Original Message -----
From: "Peter Kovalsky" <julschae at usa.net>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Saturday, April 08, 2000 4:15 AM
Subject: Refeing to substring in list of strings


> Hi,
>
> I am new to Python and experienced a little problem with referencing
> lately. I have a list of strings that I have to modify. Thereofre I chose
> a for-construct (for index in range(len(mylist)):). I found certain
> substrings that i want to extract - but don' t know how to adress these
> substrings. I tried a
> mylist[index][lborder:rborder]
> which won' r work for some reason - and I don' t know why. Can anybody
> help???






More information about the Python-list mailing list