turtle
turtle

Reputation: 8073

Finding the minimum of a nested list

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

Upvotes: 2

Views: 327

Answers (1)

icktoofay
icktoofay

Reputation: 128991

Use minimumBy, comparing, and snd:

minimumBy (comparing snd)

Upvotes: 15

Related Questions