As explained in the answer to this question for loops in python do not work by reference. Therefore, a program like that
a=[1,2,3]
for el in a:
el += 1
print(a)
will not modify a.
In c++ there is instead the possibility to have for loops either by copy or reference. For instance, the following c++ code modifies the contents of the array a
std::array<int, 3> a{1, 2, 3};
for auto& el : a
el += 1;
Is there a way to implement a syntax in python that achieve the same as the c++ loop above?
Edit: to be more precise, I am looking forward to a syntax such that, analogous to the c++ example, I have inside the loop a sort-of-reference to the elements of a.