Saturday, May 11, 2019

Python: sorted 2d list by element, reverse

要按第一個元素倒排, 第二個元素正排︰
sorted(lista, key=lambda x: (-x[0], x[1]))

No comments: