I am practising a really easy python code. I have tried to find the solution of it, but couldn't find it.
def del_contacts():
for name, number in d1.items():
if (del_name == name):
del d1.name and print ("Contact deleted!")
else:
print ("Contact does not exist")
z = input ("Do you wish to delete any of the number you added? ")
if z == 'yes':
del_name = input ("Type the name of the contact you wish to delete")
del_contacts()
else:
print ("ok")
but this gives me error in <module> del_contacts()
followed with
in del_contacts for name, numbers in d1.items(): RuntimeError: dictionary changed size during iteration
Have been facing such problem a lot. Can anyone please tell me WHY this error is happening? Any fix and what should I do in future to avoid such errors?