Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python sort a 2d array by custom function

>>> a = [
     [12, 18, 6, 3], 
     [ 4,  3, 1, 2], 
     [15,  8, 9, 6]
]
>>> a.sort(key=lambda x: x[1])
>>> a
[[4,  3,  1, 2], 
 [15, 8,  9, 6], 
 [12, 18, 6, 3]]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #sort #array #custom #function
ADD COMMENT
Topic
Name
4+6 =