sorting - Sort python list based on length, and then based on content -
i need sort list based on element's length, , based on contents. example, input [[1,2,3,4],[1,2,3],[2,3,4]]
, need [[1,2,3,4],[2,3,4],[1,2,3]]
: [1,2,3,4] has largest elements, , [2,3,4] bigger [1,2,3] in first element. input [[2,3,5],[1,2,3],[2,3,4]]
, [[2,3,5],[2,3,4],[1,2,3]]
should returned comparing element element when length of element same.
i sort list length of element, how can resort after that?
>>> = [[1,2,3,4],[1,2,3],[2,3,4]] >>> sorted(a, key=len, reverse=true) [[1, 2, 3, 4], [1, 2, 3], [2, 3, 4]]
don't. sort once.
key=lambda a: (-len(a), a)
Comments
Post a Comment