another way to sort like l.sort(key=lambda x:(x[0][0], -x[1][0]))

Peter Otten __peter__ at web.de
Tue Sep 7 10:03:44 EDT 2010


sajuptpm wrote:

> i need to implement  l.sort(key=lambda x:(x[0][0], -x[1][0])) in
> another way .I want to know what the modification needed in the 'if'
> check to sort this list of tuples in k[0][0] ascending and k[0][1]
> descending.

It seems you are not getting any closer to your goal. Perhaps it would help 
if you could explain that goal clearly rather than describing the means you 
are employing to achieve it.

> I have a list of tuples.
> 
> l = [((30,50),(70)), ((50,20),(20))]

By the way, (42) is not a tuple, it's an integer. To turn it into a 1-tuple 
you have to add a ',':

>>> (42)
42
>>> (42,)
(42,)
>>> 42,
(42,)

Peter



More information about the Python-list mailing list