sorting - Sort a list of tuples by their second element and absolute value -
sorting - Sort a list of tuples by their second element and absolute value -
how sort list
[("apple",3),("apple",-2),("pear",1)]
by sec element in tuple, , absolute value,
[("pear",1),("apple",-2),("apple",3)]
here's paraphrased approach:
import data.list import ghc.exts sortwith (abs . snd) [("apple",3),("apple",-2),("pear",1)]
you can apply problem requiring sort container transformed keys.
in case abs . snd
function used transforming ("foo", -5)
5
, sorted new keys.
sorting haskell tuples
Comments
Post a Comment