Is there a way to get multiple ngram orders using NTLK instead of obtaining a iterating over a generator?
<p>I need ngrams. I know <code>nltk.utils.ngrams</code> can be used to obtain ngrams, but in practice, the ngrams function returns a generator object. I can always iterate over it and store the ngrams in a list. But is there another, more direct way to obtaining these ngrams in a list without having to iterate over them?</p>

<p>@georg's comment pretty much nails it.</p>

<pre><code>In [12]: from nltk.util import ngrams

In [13]: g = ngrams([1,2,3,4,5], 3)

In [14]: list(g)
Out[14]: [(1, 2, 3), (2, 3, 4), (3, 4, 5)]

In [15]: g = ngrams([1,2,3,4,5], 3)

In [16]: map(lambda x: x, g)
Out[16]: [(1, 2, 3), (2, 3, 4), (3, 4, 5)]
</code></pre>

python nlp generator nltk n-gram