need insight...
David Broadwell
dbroadwell at mindspring.com
Sat Jun 24 06:53:18 EDT 2000
> The problem is that you really do not want to change the sequence you're
> using in 'for' -- the documentation, if memory serves, shows an example of
> precisely why. You'll want to make a copy of it to iterate through.. like;
>
> for item in cwd[:]:
> ...
> cwd.remove(item)
>
> Like that..see? The [:] slice copies the whole sequence.
After reading the documentation, i added the slice opperator in one
place, the one it was strictly necessary to the design to modift the
list, and in the others (with the cdw) i simply restrained myself as i
didn't NEED to modify it, and the program functioned exactly as
expected.
Thanks newsgroup. (btw: this was one of my first real coding effort
spaned from gtting pissed at having to open 18 instances of notpad to do
a simple task.)
And though it does not sho precisely why, i can understand how a loop,
iterating on indexing pointer would get confuzed as the list items
change places after a delete..
--
~We're all fallen angels who've forgotten how to fly~
Remember how: http://www.cyber-action.com/oed/dbroadwell.html
--
More information about the Python-list
mailing list