[Tutor] Changing lists in place
Paul D. Kraus
paul.kraus at gmail.com
Mon Apr 17 20:02:37 CEST 2006
I have a list that I want to change in a for loop. It changes in the loop
but the changes are not persistant outside of the loop.
I thought lists were mutuable objects so I am a bit confused.
Sample Code....
#!/usr/bin/env python
""" Testing lists """
mylist = [ 'One ', ' two', ' three ' ]
print mylist
for element in mylist:
element = element.strip()
print "<>" + element + "<>"
print mylist
Sample Output....
['One ', ' two', ' three ']
<>One<>
<>two<>
<>three<>
['One ', ' two', ' three ']
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060417/b1d0ae57/attachment.html
More information about the Tutor
mailing list