I have a 5x2 dimensional array which I want to assign specific values to, but I'm having trouble doing so even looking at multiple explanations of Python passing by value rather than reference. The relevant code is as follows:
def do_something(x, y):
x = 0
y = 0
return_value = -1 #error may occur in this code
#some complex operation is performed that manipulates x and y
return_value = 0
return return_value
def main():
result = [[0]*5]*2
for i in range(5):
do_something(result[i][0], result[i][1])
I clearly can't say result = do_something(...) because I still want to know what do_something returned to see if the complex operation is done right. Append doesn't exactly solve my problem, because x and y are manipulated inside the code. Result[i].append(...) would work if I knew what I wanted to append. But even when the complex operation goes right, the array doesn't change. (I have tried passing result, then r.append(...) but that doesn't work either) Any help?