Short answer, It depends....
It depends on what you meant by safe
. Technically there is nothing wrong modifying the variable used for iteration. When you iterate over a list or something, you're actually iterating over an iterator. It returns the value contained in the container (list, dict whatever)...
If you modify the variable returned by the iterator, you have to keep in mind about the mutability of the object you're trying to modify.
If you iterate over integers or strings, you're not actually modifying the variable
but affecting a new value to the variable name.. Thus, you're not modifying the value contained in the container.
But if you're iterating over a container with mutable objects (let say dicts).. Modifying the variable by changing the content, will have an effect on the value contained in the container since they are the same values.
But doing something like this would have no effect at all on the value in the container as you're not modifying the value pointed by the variable name but changing to which value the variable name points to:
a = [{}, {}, {}]
for x in a:
x = {'val': x}
While this will:
a = [{}, {}, {}]
for x in a:
x['v'] = 1