Skip to content

Instantly share code, notes, and snippets.

@jordanekay
Last active August 29, 2015 14:14
Show Gist options
  • Save jordanekay/5dfe0005a60ef7611a18 to your computer and use it in GitHub Desktop.
Save jordanekay/5dfe0005a60ef7611a18 to your computer and use it in GitHub Desktop.
Finding bigrams in text
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