let count_words text = let words = String.split_on_char ' ' text in let counts = Hashtbl.create 8 in List.iter (fun w -> let n = match Hashtbl.find_opt counts w with | Some n -> n + 1 | None -> 1 in Hashtbl.replace counts w n ) words; counts let max_count counts = Hashtbl.fold (fun _ v acc -> if v > acc then v else acc) counts 0 ;; max_count (count_words "the quick brown fox jumps over the lazy dog the fox")