python - How to sort in decreasing value first then increasing in second value -


this question has answer here:

let have :

student_tuples = [ ('john', 'a', 15),                    ('peter', 'b', 12),                    ('dave', 'c', 12)] 

how sort this:

student_tuples = [('john', 'a', 15), ('dave', 'c', 12), ('peter', 'b', 12)] 

what can think is:

from operator import itemgetter  sorted(student_tuples, key=itemgetter(2,0), reverse=true) 

but output be:

student_tuples = [('john', 'a', 15), ('peter', 'b', 12), ('dave', 'c', 12)] 

and not want. how can using itemgetter or other easier way?

this it:

print sorted(student_tuples, key=lambda t: (-t[2], t[0])) # [('john', 'a', 15), ('dave', 'c', 12), ('peter', 'b', 12)] 

Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -