我有一个 list
[[1, 2, 48.5], [1, 3, 66.7], [1, 4, 32.4]]
我只想获取索引为 2 处的最小值的列表,这样我就只能得到这样的列表
[1, 4, 32.4]
我尝试过使用 min() 和 max() 函数,但我无法弄清楚
最佳答案
您可以使用min
并在 key
中指定您要根据第二个索引进行排序:
from operator import itemgetter
l = [[1, 2, 48.5], [1, 3, 66.7], [1, 4, 32.4]]
min(l, key=itemgetter(2))
输出
[1, 4, 32.4]
关于python - 仅获取特定索引处具有最低值的子列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55107012/