nltk.bigrams() returns an iterator (generator specially) for bigrams. If you need a list, pass the list() value to the iterator. He also expects a sequence of elements to generate bitrams, so you need to split the text before passing it (if you haven’t):
bigrm = list(nltk.bigrams(text.split()))
To print them separated by commas, you can (in python 3):
print(*map(' '.join, bigrm), sep=', ')
If on python 2, then for example:
print ', '.join(' '.join((a, b)) for a, b in bigrm)
Note that for printing you do not need to create a list, just use an iterator.
source share