Skip to content

Instantly share code, notes, and snippets.

@fferegrino
Created September 28, 2018 06:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fferegrino/eef670975fbe465ee850f77c52df6d22 to your computer and use it in GitHub Desktop.
Save fferegrino/eef670975fbe465ee850f77c52df6d22 to your computer and use it in GitHub Desktop.
ngrams.py
def ngrams(string, n=3):
# Filter string
ngrams = zip(*[string[i:] for i in range(n)])
return [''.join(ngram) for ngram in ngrams]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment