Top "Stopiteration" questions

The Python `StopIteration` exception.

Why does next raise a 'StopIteration', but 'for' do a normal return?

In this piece of code, why does using for result in no StopIteration or is the for loop trapping all …

python iterator generator stopiteration
How to avoid StopIteration Error in python

I have a line that is pulling in variables from multiple lists and I want it to avoid the StopIteration …

python iteration stopiteration
How yield catches StopIteration exception?

Why in the example function terminates: def func(iterable): while True: val = next(iterable) yield val but if I take …

python yield stopiteration
python yield and stopiteration in one loop?

i have a generator where i would like to add an initial and final value to the actual content, it's …

python generator stopiteration
"RuntimeError: generator raised StopIteration" every time I try to run app

I am trying to run this code: import web urls = ( '/', 'index' ) if __name__ == "__main__": app = web.application(urls, …

python python-3.x runtime-error python-3.7 stopiteration
How can I get a Python generator to return None rather than StopIteration?

I am using generators to perform searches in lists like this simple example: >>> a = [1,2,3,4] >>> (…

python exception generator stopiteration
What is the difference between raise StopIteration and a return statement in generators?

I'm curious about the difference between using raise StopIteration and a return statement in generators. For example, is there any …

python generator stopiteration
Stop Iteration error when using next()

I am not able to clarify my self over the use of next() in python(3). I have a data : chr …

python error-handling next stopiteration
Iterate through list and handle StopIteration in Python beautifully

I am trying to iterate through a list, and I need to perform specific operation when and only when the …

python list iterator stopiteration
Return from an iterator and then throw StopIteration

What would be the nice way to return something from an iterator one last time when it's exhausted. I'm using …

python iterator stopiteration