首页 > 解决方案 > 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?

标签: pythonlist

解决方案


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))

推荐阅读