di=dict([(45,"Sdds"),(34,"Dffd")])
for key,di[key] in enumerate(di):
print("we are at key "+str(key)+" and value in dict "+str(di[key]))
While running this code I am getting "RuntimeError: dictionary changed size during iteration". Can you help me how to handle this error?
With syntax
for key,di[key] in enumerate(di):you're modifying the dictionary while iterating: first iteration thekey = 0and then you're trying to setdi[0]with one of the key found already in dictionary.Try this instead:
Prints: