My title might be a bit off but I didn't really know how to formulate myself.
Say I have a function that takes a data structure and maybe some other arguments and returns a value from that data structure. How do I reassign that return value?
Here's a simple example of what I want to do:
Let's say I have a function foo,
def foo(x, n):
return x[n]
and a list l,
l = [1, 2, 3, 4, 5]
what I want to do is something like this:
foo(l, 1) = 0 #this results in an error
Which I want to result in this:
l = [1, 0, 3, 4, 5]
This example may be trivial with another approach but let's imagine my function for retrieving an item from the list is more complex.
Edit: Maybe my description was too unclear, basically what I want is an assignment operator that works like setf in lisp. I want my function to return some sort of pointer to a value in a data structure. I then want to change the value that the pointer is pointing at. What I want to use it for i basically something like this: (that I don't understand why I didn't just begin with as an example)
def foo(l, indexes):
if indexes == []:
return l
else:
return foo(l[indexes[0]], indexes[1:])
l = [[1, 2], 3]
foo(l, [0, 1]) = 0 #Again this is what is not working and I understand why it's not working, I just want something that would do what you think this might do.
Which I want to result in:
l = [[1, 0], 3]