Ronny Mandal wrote:
> Assume we have a list l, containing tuples t1,t2...
>
> i.e. l = [(2,3),(3,2),(6,5)]
>
> And now I want to sort l reverse by the second element in the tuple,
> i.e the result should ideally be:
>
>  l = [(6,5),(2,3),(3,2)]
>
>
> Any ideas of how to accomplish this?

def cmpfun(a,b):
        return cmp(b[1],a[1])

l.sort(cmpfun)
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to