I have an array of objects. I am interested in writing a function that will find a specific object in a list and return a reference to it.
Imagine the following code snippet was possible:
list1 = [1,2,3]
def find(q):
return q[0]
a = find(list1)
a = 0 # This should change the object that "a" is referencing to.
print list1 # [0, 2, 3] is desired as result.
It is easy to do with pointers in C++, but how can I do it in python?
To achieve exact same semantics may not be possible but something similar can be achieved by a proxy with get/set methods, though I am not clear exactly what and why you needed this, so final solution could be much more complex or simple, anyway here is my solution
output: