I have a global variable in one function that is used as an argument for another. How can I use it as an argument without the second function changing it?
Example:
variable = []
def bar(x):
x[2] = 4
print x
def foo():
global variable
variable = [1, 2, 3, 4]
bar(variable)
print variable
Running foo()
like this would output:
[1, 2, 4, 4]
[1, 2, 4, 4]
When I want it to print:
[1, 2, 4, 4]
[1, 2, 3, 4]
So is there a way to keep the original global variable for future use while still using it in the other function?