Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding the minimum of a nested list

Tags:

haskell

I have a nested list that looks like this:

let i = [(6, 0.2), (4, 0.9), (12, 0.1)]

I'm interested in finding the element that has the smallest second element:

(12, 0.1)

I was trying to use minimum, but obviously that doesn't work. How can I find the minimum of a nested list?

minimum (\(x, y) -> y) lst
like image 702
turtle Avatar asked Dec 17 '25 19:12

turtle


1 Answers

Use minimumBy, comparing, and snd:

minimumBy (comparing snd)
like image 151
icktoofay Avatar answered Dec 20 '25 12:12

icktoofay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!