Last active
August 29, 2015 14:14
-
-
Save jordanekay/5dfe0005a60ef7611a18 to your computer and use it in GitHub Desktop.
Finding bigrams in text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func bigrams(text: String) -> [(String, String)] { | |
let words = split(text) { $0 == " " } | |
return Array(Zip2(words, words[1..<words.count])) | |
} | |
1> println(bigrams("one two three four five")) | |
[(one, two), (two, three), (three, four), (four, five)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment