1C=02f={}3jiao={'Script One': 122000,'Script two': 189999,4 'script three': 99999,'Script 4': 25000000,'Jiaoben': 126}5 forIinchjiao.values ():6c=c+I7average=c/Len (Jiao)8 forLiinchJiao.keys ():9 ifJiao[li]>Average:Ten delJiao[li] One #F.setdefault (Li,jiao[li]) A Print(average) - Print(LI)
The error occurs at this point:
Runtimeerror:dictionary changed size during iteration # dictionary changes the size of the dictionary at iteration time
There are two ways to find this problem online: 1. is deleted by converting to a list;
2. Copy for online
for inch # change from result to Result.keys () if not Result[key]: del Result[key] Continue
The second Test did not solve the problem, the warning still exists,
The workaround is not to delete it and reassign the data that is not deleted to a new dictionary.
Python-encountered dictionary changed size during iteration