1

I have a list, which I wish to sort. List is made of items with two elements each. I wish to sort wrt to second element only. Thus, I am almost sure that

L = [[4,2],[5,2]]
sorted(L)

won't do the job.

How to proceed? I come through answers but did not understand what could apply to problem.

Thansk!

  • There are many more here like that here on SO. – Martijn Pieters Feb 24 '13 at 14:43
  • I spotted this question, did not have a clue whether it was also a possible syntax for sorted (not only max), or how to write it properly. thanks anyway for tip. –  Feb 24 '13 at 15:02

1 Answers1

1
from operator import itemgetter
sorted(L, key=itemgetter(1))

Returns the sorted list L, sorted by key the second item in each element of L.

danodonovan
  • 19,636
  • 10
  • 70
  • 78