llm_engineering icon indicating copy to clipboard operation
llm_engineering copied to clipboard

Extend Intermediate Python `generators` examples

Open Carbaz opened this issue 7 months ago • 0 comments

Added some extra examples and explanations for generator expressions to the Intermediate Python Notebook.

  • How to create generators using comprehensions alike syntax.

  • Exposing generators depletion, on my experience is a typical issue new learners face.

    Specially when using iterators as they do not raise an exception and just returns/do nothing when a depleted generator is provided.

    This may lead to a "IDK Why this does not work now if it worked before", specially on Notebooks where you can run the "consumer" cell twice in a row getting "nothing" on the second run. 😉

  • How we get memory benefits from using generators and how they allow a huge dataset generator scenario that will not fit complete on memory.

  • Example of a generator encapsulating an external resource, behaving as an infinite generator on demand without compromising memory.

    This may be handy to work with stream completions for example.

There is also a typo fixed detected by the spell checker of my IDE.

Carbaz avatar May 28 '25 19:05 Carbaz