Created
September 28, 2018 06:45
-
-
Save fferegrino/eef670975fbe465ee850f77c52df6d22 to your computer and use it in GitHub Desktop.
ngrams.py
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
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