extract n grams from text python

Solutions on MaxInterview for extract n grams from text python by the best coders in the world

showing results for - "extract n grams from text python"
Selma
08 Aug 2019
1from nltk import ngrams
2
3sentence = 'this is a foo bar sentences and i want to ngramize it'
4
5n = 6
6sixgrams = ngrams(sentence.split(), n)
7
8for grams in sixgrams:
9  print grams