About 50 results
Open links in new tab
  1. Understanding generators in Python - Stack Overflow

    Note: this post assumes Python 3.x syntax.† A generator is simply a function which returns an object on which you can call next, such that for every call it returns some value, until it raises a StopIteration …

  2. What does the "yield" keyword do in Python? - Stack Overflow

    Oct 24, 2008 · Yield in Python used to create a generator function. Generator function behaves like an iterator, which can be used in loop to retrieve items one at a time. When a generator function is …

  3. python - What can you use generator functions for? - Stack Overflow

    The generator approach is that the work-function (now a generator) knows nothing about the callback, and merely yields whenever it wants to report something. The caller, instead of writing a separate …

  4. How can I type hint a generator in Python 3? [duplicate]

    A Generator object is produced by calling a generator function, which is defined using the yield keyword. The Generator type is unique as it has two additional type parameters for its send and return types, …

  5. python - Difference between function and generator? - Stack Overflow

    Apr 25, 2015 · A generator is very similar to a function that returns an array, in that a generator has parameters, can be called, and generates a sequence of values. However, instead of building an …

  6. Difference between Python's Generators and Iterators

    Every generator is an iterator, but not vice versa. A generator is built by calling a function that has one or more yield expressions (yield statements, in Python 2.5 and earlier), and is an object that meets the …

  7. python - How to loop through a generator - Stack Overflow

    I would like to measure the execution time of each generator invocation. What's a reasonably elegant & pythonic way to structure a loop that can get the timestamp before and after each invocation?

  8. What is the return type hint of a generator function?

    Apr 27, 2017 · 102 As of Python 3.9, you can annotate a generator using the Generator[YieldType, SendType, ReturnType] generic type from collections.abc. For example:

  9. What does the yield keyword do in Python, and when should I use a ...

    I'm trying to optimize a function that processes a very large file line by line. I’ve seen some examples use the yield keyword, but I don't fully understand how it differs from return. When I use yield, the …

  10. generator - Proper type annotation of Python functions with yield ...

    Jul 17, 2016 · I searched, but found no documentation for the 3 type parameters of Generator in the official typing documentation for Python 3.5.2 - beyond a truly cryptic mention of...