Sep-24-2019, 01:20 PM
Hello everyone,
I would like to sort a multidimensional list by the second column.
Example:
I did try numpy arrays too, but I just can't find the right way.
Can anyone help me with this problem?
thank you very much!
/ToffieFaye
I would like to sort a multidimensional list by the second column.
Example:
x = [ [1,18,2], [2,9,4], [3,1,1] ] x = sorted(x, key=lambda x: x[2]) print(x)The output I am looking for should be:
[ [3,1,1], [2,9,4], [1,18,2] ]Unfortunately lamdba sorts like this:
[ [3,1,1], [1,18,2], [2,9,4] ]So lamda does put 18 below 9, because of the '1' in the front.
I did try numpy arrays too, but I just can't find the right way.
Can anyone help me with this problem?
thank you very much!
/ToffieFaye