1
def findMaxDiff(l):
'list(list(int)), returns index of the row with the maximum difference between elements and the value of the difference in that row'
return (max(max(a) - min(a) for a in l), l.index(max(l, key=max)))
虽然我已经得到它返回最大值的值,但我不能完全得到它返回该列表的正确索引。它在这种情况下工作正常:返回最大值的列表索引
>>> findMaxDiff([[12,3,50,17], [10,5,9,100,31], [5,3,1]])
(95, 1)
但在这种情况下不。
>>> findMaxDiff([[0,10],[99,99]])
(10, 1)
>>> findMaxDiff([[1],[2],[3]])
(0, 2)
对于第一个应该返回(10,0),第二个应该返回(0,0)。我试过key = sum和key = max,但都返回相同的东西。
这在返回(10,0)的工作,但奇怪的是仍然返回(0,2)。 – iKyriaki 2013-02-11 05:51:25
嗯,这是最后一种情况的三种方式。在这个例子中,我看不出(0,0)如何比(0,2)更正确。 – wim 2013-02-11 05:53:08
嗯..我只是将代码更改为此,因为它确实消除了(10,1)问题,其他所有工作都完美无缺。非常感谢你。 – iKyriaki 2013-02-11 05:55:37