I have the the following list: mylist = [[1,2,3], [4,5,6], [7,8,9]]. I want to basically update its last row and 1st column value which in coding terms would be this: mylist[-1][1].
Basically, what I want to update this is with the maximum value between the value present at this specific row and column and the value at its last row and 0th column value which is: mylist[-1][0]. Something like the following:
mylist[-1][1] = max(mylist[-1][1], mylist[-1][0])
The values inside the max function can change. This is just one small example. My main goal is to try and find a way of updating the value inside this 2D list.
I think it is also worth mentioning that often in Elixir you don’t actually want/need random access, and most of the time there is an efficient way to do it with plain lists by using the right function in the Enum library (or a for comprehension, or a recursive function).
If I understand your use case correctly, Enum.scan/2 might help to keep track of the maximum so far within each row: