The problem is not really a problem in how iterators work in python, and not how assignment works in most python types. When the crawler tries to rewrite the lett value, which is really an alias ab [index] and should seem to work logically, this is not really what is happening, but lett (the reference or lett pointer, not the value that it indicates to) is reassigned. to indicate the constant of the new value, this is very different from overwriting bytes at the memory location it points to. This way of working is necessary to allow duck pythons to be printed, where the variable name may eventually point to different types with different sizes. See this page for more details: http://gestaltrevision.be/wiki/python/aliases
The closest we could achieve is a manual type "mutable integer", which will allow us to change its base value, unlike python ints. However, there is little point in moving here, as this has already been explained in this matter . Although the question is completely different, it is one and the same main problem, and the solution is equally acceptable. However, if you do this, I would first think if you can rebuild your code to avoid this, in the first place, since this is a rather dangerous and accident-prone way of working.
Here is an example from the answer to the question "increment of int object" for a full explanation of how to hack this together, see the question related above, note that this example includes only decrement, other operators should be implemented in the same way:
import sys class FakeInt(int): def __init__(self, *arg, **kwarg): self._decr = False int.__init__(self, *arg, **kwarg) def __neg__(self): if self._decr: upLocals = sys._getframe(1).f_locals keys, values = zip(*upLocals.items()) i = list(values).index(self) result = FakeInt(self-1) upLocals[keys[i]]=result return result self._decr = not self._decr return self
source share