I am not sure if this makes any sense in python, but consider I have two variables x
and y
:
x = 1
y = x
Now, at a later time when I change x
, I want y
to see this change. that is if I do
x = 2
I want y
to be 2 also. Is there a way to do reference(x) = 2
, so that all variables that were assigned to x
will see this change?
One way to make this work is to use lists for everything as described here. This would work if I had defined x
as list, so if
x = [1]
y = x
then, doing x.clear()
and x.append(val) for val in new_list
would work, and y
will change according to the new list.
But I would like to do it for any type, because otherwise I will need to revisit most of my codebase. Is there a mutable type so I don't have to redefine all my y
's to be x[0]
.
Any suggestion is appreciated.