Let's say we have a Python dictionary d
, and we're iterating over it like so:
for k,v in d.iteritems():
del d[f(k)] # remove some item
d[g(k)] = v # add a new item
(f
and g
are just some black-box transformations.)
In other words, we try to add/remove items to d
while iterating over it using iteritems
.
Is this well defined? Could you provide some references to support your answer?
(It's pretty obvious how to fix this if it's broken, so this isn't the angle I am after.)
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…