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

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

ubuntu - Bash Script to Check That Files Are Being Created -