Guest User

Untitled

a guest
Jul 18th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. let book = Map [(1, ["daniel"; "martin"; "bella"]); (2, ["daniel"; "martin"]); (3, ["bella"])];;
  2.  
  3. let words = book |> Map.toList |> List.map snd |> List.concat |> Set.ofList
  4.  
  5. let inverseBook =
  6. [ for word in words do
  7. let pages =
  8. book
  9. |> Map.toList
  10. |> List.choose (fun (page, pageWords) -> if List.exists ((=) word) pageWords then Some page else None)
  11. yield word, pages ]
Add Comment
Please, Sign In to add comment