0

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?

Jonas
  • 121,568
  • 97
  • 310
  • 388
Narcis
  • 441
  • 1
  • 3
  • 12
  • The code you show does not provide enough information about the problem, please provide a reproducible example https://stackoverflow.com/help/minimal-reproducible-example – ScootCork Apr 30 '21 at 16:25
  • Can you think of a reason that `parser.parse(t)` might produce an empty sequence? What do you think should happen when you use `next` with an empty sequence? What does the documentation say about that? What happened when you tried putting `python next stopiteration` into a search engine? – Karl Knechtel Apr 30 '21 at 16:30
  • Show us the `try...except` code that raised this error. – BoarGules Apr 30 '21 at 16:37

1 Answers1

0

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.

Narcis
  • 441
  • 1
  • 3
  • 12