ocaml - Check element in a list -
i have example:
let l = [0;1;2] let l1 = [0;2]
from list l
check whether or not there element of l
belong l1
; if yes return list of pair, instance [(1,0); (1;2)]
for this, should iterate through each element in l. check if first element of l element of l1. if is, filter out elements equal. length of list of equal elements first character in tuple go return list.
let check_list l l1 = let rec check l l1 combined = match l |[] -> combined |(h::t) -> if (list.mem h l1) check t l1 ((list.length(list.filter (fun x -> h=x) l1),h)::combined) else check t l1 combined in check l l1 []
Comments
Post a Comment