Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

RuntimeError: dictionary changed size during iteration

In Python 3.x and 2.x you can use use list to force a copy of the keys to be made:

for i in list(d):

In Python 2.x calling keys made a copy of the keys that you could iterate over while modifying the dict:

for i in d.keys():
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #dictionary #changed #size #iteration
ADD COMMENT
Topic
Name
8+3 =