0

The following python snippet results in a "dictionary changed size during iteration" error. But I do not modify the dictionary at all. Any help would be appreciated.

for key1 in d1:
    key2 = d1[key1]
    for keys in key2:
        values = d1[keys]
        if( key1 in values):
            print '\n\n', key1, keys, '\n'

ERROR:

Traceback (most recent call last):
      File "C:/Nandita/Python/remove_duplicates.py", line 12, in <module>
        for key1 in d1:
    RuntimeError: dictionary changed size during iteration

EDIT: d1 looks like this

1: 2, 4
2: 4, 7, 9
4: 1, 2, 5
6: 1, 7

Nandita Damaraju
  • 193
  • 1
  • 2
  • 11

0 Answers0