KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
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? See also How to avoid "RuntimeError: dictionary changed size during iteration" error? for the separate question of how to avoid the problem.
Tags (comma-separated)
Save Edits
Cancel