I have a 2 lists of strings
eg:
listx = ["name","age","rank"]
input = ["name","age"]
How can I compare the two lists to check whether the listx
contains "name"
& "age"
given in input
?
I have a 2 lists of strings
eg:
listx = ["name","age","rank"]
input = ["name","age"]
How can I compare the two lists to check whether the listx
contains "name"
& "age"
given in input
?
Is this homework? :)
You need to create one or two recursive functions to walk through both lists, and search for every string in the input.
Or, you could look up some good functions in the Prelude that helps here.
all (flip elem listx) input
comes to mind. No idea how efficient it is though...
B is a subset of A iff B \ A is empty
so another way to do it is
import Data.List ((\\))
null (input \\ listx)
One more way.
import Data.Set
(fromList input) `isSubsetOf` (fromList listX)