Check, if list is a sublist of another list

后端 未结 2 1984
有刺的猬
有刺的猬 2021-01-19 08:57

I\'d like to write a function that checks if one list is a sublist of another list. I wrote this, but it is not working, but I need something like this, I guess. Thanks for

2条回答
  •  情话喂你
    2021-01-19 09:37

    You could use the function intersect like this:

    intersect [list1] [list2] == [list1]

    *Test> intersect [] [] == []
    True
    *Test> intersect [1] [] == [1]
    False
    *Test> intersect [2,4,6,4] [9,5,4,2,6,3,3] == [2,4,6,4]
    True
    *Test> intersect [1,2,3] [3,2,5,4] == [1,2,3]
    False
    
    

    You will have to import Data.List for this.

提交回复
热议问题