Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3
There is no loop in your generator. Your if statement runs only once and then the first word is yielded out. At next iteration your code throws StopIteration error because there are no more yields. It's due to the way generators are implemented, it has nothing to do whith your if statement. Try replacing raise StopIteration with pass(or remove the if statement) and you'll get the same output. Gangadhar If you need help implementing a generator that yields word by word then ask here and I will guide you. I'm not giving you the solution now to avoid spoiling your learning process.
11th Jun 2020, 6:24 AM
Kevin ★