x = {0: None}
for i in x:
del x[i]
x[i+1] = None
print(i)
This code on execution gives the output as
0
1
2
3
4
By the logic of the loop it seems it should either go on forever or give an error when the dictionary becomes zero. But neither happens. Can someone explain how? I'm running it in python 3.6