What does `yield from` do?
AdvancedConceptLanguage essentials & functions
Answer
yield from iterable yields every item of a sub-iterable, and for sub-generators it also forwards send(), throw() and close() and returns the sub-generator's return value. In everyday DevOps code it is simply the clean way to flatten: yield from page["Reservations"] instead of a nested for with yield. It is also how generator-based coroutines were built before async/await.
More on Language essentials & functions
Why is Python the default scripting language in so many DevOps teams, and where would you not use it?BeginnerWhat is the difference between mutable and immutable types? Give examples.BeginnerWhat does assignment do in Python, and how do shallow and deep copies differ?BeginnerExplain the mutable default argument bug and how to fix it.IntermediateWhat is the difference between `==` and `is`?BeginnerWhat values are "falsy" in Python, and why does it matter in scripts?Beginner