Re: [Tutor] Changing lists in place

2006-04-17 Thread Alan Gauld
> I have a list that I want to change in a for loop. Thats nearly always a bad thing to do. Its like the old cartoon of the guy vcutting off the branch of the tree while sitting on it. Python can get very confused. Either make a copy and change the copy or use a while loop and an index. Howe

Re: [Tutor] Changing lists in place

2006-04-17 Thread Paul D. Eden
Very true. Paul Kent Johnson wrote: > Paul D. Eden wrote: > >>Lists are mutable, you are right. >> >>But the code you gave does not change the list. It changes the variable >>element which is separate from the list myList. >> >>If you want to change the list try something like this: >> >>mylis

Re: [Tutor] Changing lists in place

2006-04-17 Thread Kent Johnson
Paul D. Eden wrote: > Lists are mutable, you are right. > > But the code you gave does not change the list. It changes the variable > element which is separate from the list myList. > > If you want to change the list try something like this: > > mylist = [ 'One', ' two', ' three ' ]

Re: [Tutor] Changing lists in place

2006-04-17 Thread Bob Gailer
Paul D. Kraus wrote: > 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 They are. > so I am a bit confused. > > Sample Code > #!/usr/bin/env python > """ Testing lists ""

Re: [Tutor] Changing lists in place

2006-04-17 Thread Paul D. Eden
Lists are mutable, you are right. But the code you gave does not change the list. It changes the variable element which is separate from the list myList. If you want to change the list try something like this: mylist = [ 'One', ' two', ' three ' ] print mylist newlist = [] for elemen