Skip to content

Instantly share code, notes, and snippets.

@bandrzejczak
Created February 9, 2018 21:27
Show Gist options
  • Save bandrzejczak/99541db196aae81c0f53a4e142d34263 to your computer and use it in GitHub Desktop.
Save bandrzejczak/99541db196aae81c0f53a4e142d34263 to your computer and use it in GitHub Desktop.
def makeWordMap(sentences: List[String]):
Map[String, List[String]] = {
val initMap = Map.empty[String, List[String]]
sentences.foldLeft(initMap) { (map1, sentence) =>
words(sentence).foldLeft(map1) { (map2, word) =>
map2 +
(word -> (sentence :: map2.getOrElse(word, Nil)))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment