Return a list of Integer values that is not within a range of numbers in an existing list:

后端 未结 1 328
夕颜
夕颜 2021-01-27 13:42

I have a list of values:

[0,7,4,5,3,1,4,5,5,1,7,0,7,7,0]

and would like to return any values that are not in the range of [1..8]

相关标签:
1条回答
  • 2021-01-27 14:20

    Use filter to keep elements that satisfies a condition.

    Prelude> filter (`notElem` theBigListOfValues) [1..8]
    [2,6,8]
    

    Or just take the complement using the (\\) operator.

    Prelude> import Data.List
    Prelude Data.List> [1..8] \\ theBigListOfValues
    [2,6,8]
    
    0 讨论(0)
提交回复
热议问题