Is it possible to iterate through a dictionary while updating a separate dictionary? I tried to create a copy of my original dictionary and edit that one but I'm still getting an error
d = {30:3, 54:5, 16:2}
r = d
for k,v in d.items():
biggest = max(d,key = d.get)
del(r[biggest])
I need to find the largest value of the dictionary each time it loops through. Then I need to remove that item from the dictionary so I can find the next largest item.
The error I get when I run this code is as follows.
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
for k,v in d.items():
RuntimeError: dictionary changed size during iteration