Hi list,

I was banging my head about a pythonic way of doing the following,

Given a nested list, how do I sort the uppermost list based on one key and
when a special condition occurs a sort on another key should be performed?

For example, [[1,2], [2, 2], [3, 2], [4, 0]] would be sorted, in my example
as, [[4, 0], [3, 2], [2, 2], [1, 2]]. That is, sort on the second value and
in case they are equal, reverse sort on the first value.

I tried doing this using sorted and using a custom cmp function but not
sure about how to define the cmp function.

-- 
Sarma Tangirala,
Class of 2012,
Department of Information Science and Technology,
College of Engineering Guindy - Anna University
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to