I have the following list of tuples:
[("a",6),("b",1),("c",2),("d",4),("e",1),("f",1),("g",5),("h",3),("i",1),("j",2)]
but would like to order the tuples in the list by the snd element of the tuple. That way, I get an answer similar to:
[("b",1),("e",1),("f",1),("i",1),("c",2),("j",2),("h",3),("d",4),("g",5),("a",6)]
(i.e. the list is ordered by the second (snd) of each tuple.
sortBy (comparing snd)
where sortBy is in List and comparing is in Data.Ord.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With