lstB = lstA The above just points lstB to lstA and *does not* create a copy. If you do not understand "pointers", think of lstB an alias of lstA. If you want to create a copy you need to explicitly do it.
lstB = [] for word in lstA : lstB.append(word) or shortcut lstB = lstA[:] So, even though you created a new variable lstB it was actually modifying lstA. HTH Aditya On 10/12/07, Dick Moores <[EMAIL PROTECTED]> wrote: > > At 11:25 PM 10/11/2007, Aditya Lal wrote: > >Hi Dick, > > > >You are deleting from the SAME list that you are traversing. This > >results in problems. > > Aditya, > > Well, if deleting from the same list I'm traversing is the problem, > why doesn't inserting the line > lstB = lstA > > and deleting from lstB clear it up? The output is exactly the same. > I'm really puzzled. See <http://www.rcblue.com/Python/buggy_For_Web2.py> > > I thank you for showing me another way to get the result I want, but > first I want to know why my code didn't work. > > Dick > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- Aditya
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor