I need to sort a list of vectors, based on the last element of the vector. I thought it should be possible with the list.sort(key=something)
method, but all I find are examples using the sorted()
function, and I'm not clear how that key=something could point to the last element of the vector.
Here is my list of 3 vectors:
[ [1,2], [2,3], [3,1] ]
I need to reorder the 3 vectors by using the second element of each vector, and the result should produce the following
[ [3,1], [1,2], [2,3] ]