Python implementation of Ngram