I want pop out all the large values and its keys in a dictionary, and keep the smallest. Here is the part of my program
for key,value in dictionary.items():
You can use copy.deepcopy to make a copy of the original dict, loop over the copy while change the original one.
from copy import deepcopy d=dict() for i in range(5): d[i]=str(i) k=deepcopy(d) d[2]="22" print(k[2]) #The result will be 2.
Your problem is iterate over something that you are changing.