Top "Generator" questions

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

Python Empty Generator Function

In python, one can easily define an iterator function, by putting the yield keyword in the function's body, such as: …

python generator
How to look ahead one element (peek) in a Python generator?

I can't figure out how to look ahead one element in a Python generator. As soon as I look it's …

python generator peek
Out of curiosity: How are serial numbers generated? Hints, Algorithms?

I wondering about how serial number generators and validator work. My aim would be to generate a serial number with …

algorithm generator validation serial-number
How to write a generator class?

I see lot of examples of generator functions, but I want to know how to write generators for classes. Lets …

python generator fibonacci
enumerate()-ing a generator in Python

I'd like to know what happens when I pass the result of a generator function to python's enumerate(). Example: def …

python iterator generator enumerate
What's the shortest way to count the number of items in a generator/iterator?

If I want the number of items in an iterable without caring about the elements themselves, what would be the …

python iterator generator iterable
Python: using a recursive algorithm as a generator

Recently I wrote a function to generate certain sequences with nontrivial constraints. The problem came with a natural recursive solution. …

python recursion generator
Get the nth item of a generator in Python

Is there a more syntactically concise way of writing the following? gen = (i for i in xrange(10)) index = 5 for i, …

python generator
Meaning of validation_steps in Keras Sequential fit_generator parameter list

I am using Keras with a Tensorflow backend in Python. To be more precise tensorflow 1.2.1 and its build-in contrib.keras …

parameters keras generator data-fitting
Why is there no first(iterable) built-in function in Python?

I'm wondering if there's a reason that there's no first(iterable) in the Python built-in functions, somewhat similar to any(…

python iterator generator