Strange behaviour with reversed()
bignose+hates-spam at benfinney.id.au
Thu Oct 18 07:24:27 CEST 2007
Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au> writes:
> and help(reversed) but neither gives any insight to what happens
> when you use reversed() on a sequence, then modify the sequence.
I would think the answer is the same for any question about modifying
sequences while iterating: "undefined, therefore don't do that".
In other words, if you think you'll be modifying the sequence during
iteration (even if you're iterating indirectly via something like
reversed()), iterate over a copy instead.
\ "Professionalism has no place in art, and hacking is art. |
`\ Software Engineering might be science; but that's not what I |
_o__) do. I'm a hacker, not an engineer." -- Jamie W. Zawinski |
More information about the Python-list