【发布时间】:2017-06-30 18:53:41
【问题描述】:
我正在尝试按 2 元组中元素的比率对列表 L 进行排序。
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)]
到现在为止
L[:] = sorted(L,key = lambda ratio: ratio[0]/ratio[1])
但它以某种方式给了我[(2, 4),(1, 3),(3, 5), (8, 5), (9, 4)]的列表
我哪里做错了?
【问题讨论】:
-
/for ints 是 Python 2 上的地板除法。
标签: python python-2.7 list sorting