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

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -