StopIteration Error when using next in Python 3 using nltk

169 Views Asked by At

I want to run a code in Python 3. It works in Python 2.7 and the input is not empty. Some parts of the code are as follows:

parser = nltk.ChartParser(zinc_grammar.GCFG)
parse_trees = [next(parser.parse(t)) for t in tokens]

But it shows the StopIteration error on the bottom line. Does anyone know how to solve it? Is there any alternative for it?

1

There are 1 best solutions below

0
On

I realized that the problem is from the definition of the tokens because I used lambda function. I changed it and the problem is solved.