python - Find the smallest element in a list of list
问题描述
Given the following list:
f = [[1, 19], [1, 19], [1, 19], [2, 18], [16, 4], [10, 10]]
I want to get the smallest value of each sub-list and create:
f1 = [1, 1, 1, 2, 4, 10]
How can I do this?
解决方案
Since it's a Python list, you can use min
function for each sub-list using list-comprehension
[min(subList) for subList in f]
OUTPUT:
[1, 1, 1, 2, 4, 10]
Or, you can even combine min
and map
together
list(map(min,f))
推荐阅读
- python - 如何将我的 python 输出导出到 GoogleSheets 或 Excel Doc?(首选床单)
- php - 在 preg_replace 中使用子字符串
- java - 尝试构建工作区时 STS/Eclipse 权限被拒绝错误
- java - 使用 Java mousePress、mouseMove 和 mouseRelease 进行单击和拖动
- c# - 需要与 MAC 的活动连接。请确保已建立连接
- angular - 孙子组件选择或在组件中重用代码
- javascript - 隐藏具有特定图例项的多个数据集
- vb.net - 如何使用 VB.NET 获取一个月的最后五天
- jquery - 如何通过 jquery 获取属性列表?
- javascript - 无法使用 CSV 文件到数组的方法将数据推送到数组