-1

I am trying to sort the list L by the ratio of the elements in the 2-tuples.

Parameters
----------
L : {list} of 2-tuples ({tuple}) of {int}

Returns
-------
None   

Example
-------
>>> L = [(2, 4), (8, 5), (1, 3), (9, 4), (3, 5)]
>>> sort_by_ratio(L)
>>> L
[(1, 3), (2, 4), (3, 5), (8, 5), (9, 4)]

So far I have

L[:] = sorted(L,key = lambda ratio: ratio[0]/ratio[1])

but it somehow gave me a list of [(2, 4),(1, 3),(3, 5), (8, 5), (9, 4)]

Where did I do wrong?

Meruemu
  • 611
  • 1
  • 8
  • 28

1 Answers1

1
L = [(2, 4), (8, 5), (1, 3), (9, 4), (3, 5)]
L[:] = sorted(L,key = lambda ratio: 1.*ratio[0]/ratio[1])
print L
Ghilas BELHADJ
  • 13,412
  • 10
  • 59
  • 99