Skip to content

Instantly share code, notes, and snippets.

@puneetlakhina
Created November 30, 2011 10:09
Show Gist options
  • Save puneetlakhina/1408564 to your computer and use it in GitHub Desktop.
Save puneetlakhina/1408564 to your computer and use it in GitHub Desktop.
Make n grams from a list of words
def ngram(words,n):
return ["_".join(words[i:i+n]) for i in range(0,len(words)-n+1)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment