while running some scripts on dictionaries i found a problem with the functions using .pop in a loop on a dictionary only works once. an example:
randomDictionary = {
"PERSON1":{"NAME":"Cheese man","AGE":24},
"PERSON2":{"NAME":"Pepsi Man","AGE":26},
"PERSON3":{"NAME":"Something else man","AGE":30},
"PERSON2":{"NAME":"Pepsi Man","AGE":26},
}
for i in randomDictionary:
if randomDictionary[i]["NAME"] == "Pepsi Man":
randomDictionary.pop(i)
and the error is:
Traceback (most recent call last):
File "f:\stuff\visualbackup\Special projects\testingeverything.py", line 7, in <module>
for i in randomDictionary:
RuntimeError: dictionary changed size during iteration
How do i fix this?
I tried to pop items from a dictionary in a loop, except that i got an error.