I’m having a hard time when I try to order a list of lists by the second element, something like this
list = [[_,B,_,_,_],[_,A,_,_,_],[_,C,_,_,_]]
into this:
list = [[_,A,_,_,_],[_,B,_,_,_],[_,C,_,_,_]]
I’ve tried:
sortBy compare $ [([1,2]!!1),([2,3]!!1)]
But it filters the seconds elements and order that into [2,3].
What you tried to do is sort the list
[([1,2]!!1),([2,3]!!1)], which is equivalent to[2, 3], bycompare. What you want to do is usesortBywith a function that first gets the second element and then compares:Then take the list you have and apply this function to it:
You can make this function neater by using
onfromData.Function:You can also use
comparingfromData.Ord: