Skip to content

Instantly share code, notes, and snippets.

@dgfitch
Created December 29, 2010 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgfitch/758837 to your computer and use it in GitHub Desktop.
Save dgfitch/758837 to your computer and use it in GitHub Desktop.
let book = Map [(1, ["daniel"; "martin"; "bella"]); (2, ["daniel"; "martin"]); (3, ["bella"])];;
let words = book |> Map.toList |> List.map snd |> List.concat |> Set.ofList
let inverseBook =
[ for word in words do
let pages =
book
|> Map.toList
|> List.choose (fun (page, pageWords) -> if List.exists ((=) word) pageWords then Some page else None)
yield word, pages ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment