Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python sort list by length of sublist

In [6]: a = [['a', 'b', 'c'], ['d', 'e'], ['f', 'g', 'h'], ['i', 'j', 'k', 'l'], ['m', 'n'], ['o']]

In [7]: a.sort(key=len)

In [8]: print a
[['o'], ['d', 'e'], ['m', 'n'], ['a', 'b', 'c'], ['f', 'g', 'h'], ['i', 'j', 'k', 'l']]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #sort #list #length #sublist
ADD COMMENT
Topic
Name
8+9 =