[Tutor] modifying list of strings during iteration (without index)?

Jeff Kowalczyk jtk@yahoo.com
Wed Jan 1 19:30:03 2003


I'm mortified that I don't know the answer to this: What technique is used when you want
to iterate over a list of strings (or other items) and reassign/modify the iteration
element in place (i.e without making a copy or new list)? I'm trying not to stray into
lambda/map territory for this particular piece of code, I want to see how its done with an
ordinary iteration first.

li = ['SELECT string 1' ,'   string2', '       string3']

>>> for item in li:
...        item.strip()
(or )
>>> for item in li:
...        item = item.strip()

For the moment, I'm just assigning to a new list...

Thanks.