"Gregory Ewing" wrote in message news:fnccd8ff3s...@mid.individual.net...
Chris Angelico wrote:
> It is an error to mutate the dictionary *and then continue to iterate
> over it*.
But if you're processing the last key, and you add one so
that it's no longer the last key, what should happen?
My feeling is that this should be an error, because it's
not clear whether iteration should stop at that point
or not.
I agree. A normal dictionary raises an exception. I think that an
OrderedDict should do so as well.
In fact this was the reason for my intermittent error. I was adding a key
while iterating, which was an error. But if I happened to be on the last key
at the time, it did not raise an exception. If I was on a previous key, it
did raise an exception.
Frank
--
https://mail.python.org/mailman/listinfo/python-list