Python:字典在迭代期间改变了大小"

时间:2015-01-23 08:13:18

标签: python python-2.7 dictionary

以下python代码段会导致"dictionary changed size during iteration"错误。但我根本不修改字典。任何帮助,将不胜感激。

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

编辑: d1看起来像这样

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

0 个答案:

没有答案