1 2 3 4 5 6 7 8 9 10 11 | def wordOccurrences(w: Word): Occurrences = { val chars = w.toLowerCase.toList val map = chars.groupBy((element: Char) => element) map {case(c, e) =>(c, e.length)} map.toList.sorted } /** Converts a sentence into its character occurrence list. */ def sentenceOccurrences(s: Sentence): Occurrences = wordOccurrences(s.foldLeft("")(_ ++ _)) lazy val dictionaryByOccurrences: Map[Occurrences, List[Word]] = dictionary groupBy wordOccurrences |