Top "Generator" questions

A generator is a generalisation of a subroutine, primarily used to simplify the writing of iterators.

Return in generator together with yield in Python 3.3

In Python 2 there was an error when return was together with yield in function definition. But for this code in …

python python-3.x generator
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
How to make string primary key hibernate. @GeneratedValue strategies

My goal is to create an entity Device that has a unique field IMEI and I would like to use …

hibernate spring-mvc generator spring-roo
Handle an exception thrown in a generator

I've got a generator and a function that consumes it: def read(): while something(): yield something_else() def process(): for …

python exception generator
Can generators be recursive?

I naively tried to create a recursive generator. Didn't work. This is what I did: def recursive_generator(lis): yield …

python recursion generator
Coroutine vs Continuation vs Generator

What is the difference between a coroutine and a continuation and a generator ?

generator continuations coroutine
Converting "yield from" statement to Python 2.7 code

I had a code below in Python 3.2 and I wanted to run it in Python 2.7. I did convert it (have …

python generator python-2.x yield yield-from
Python: generator expression vs. yield

In Python, is there any difference between creating a generator object through a generator expression versus using the yield statement? …

python python-3.x generator yield
Python random sample with a generator / iterable / iterator

Do you know if there is a way to get python's random.sample to work with a generator object. I …

python random generator
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