Conventions for iterators
Jason Orendorff
jason at jorendorff.com
Fri Feb 1 00:47:02 EST 2002
> So, obviously, behavior 2 is "best." But I was wondering what the
> python community expects/requires. Is the idiom such that solution 2 is
> "required," and everyone will expect an object's iterator to work that
> way, or is it more of a caveat emptor situation, and you had better red
> the module's documentation to see how the module handles this situation?
Caveat emptor. Look at what dictionaries do.
x = {'a': 3, 'b': 9, 'c': 12, 'd': 18}
for k in x:
if x[k] > 9:
del x[k]
RuntimeError: dictionary changed size during iteration
## Jason Orendorff http://www.jorendorff.com/
More information about the Python-list
mailing list