Skip to content

Instantly share code, notes, and snippets.

@acrymble
Created July 5, 2011 20:02
Show Gist options
  • Select an option

  • Save acrymble/1065778 to your computer and use it in GitHub Desktop.

Select an option

Save acrymble/1065778 to your computer and use it in GitHub Desktop.
Python get Ngrams
# Given a list of words and a number n, return a list
# of n-grams.
def getNGrams(wordlist, n):
return [wordlist[i:i+n] for i in range(len(wordlist)-(n-1))]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment