Level 1 : How does yield from affect nested generators?


def sub_generator():
    yield 1
    yield 2

def main_generator():
    yield 0
    yield from sub_generator()
    yield 3

print(list(main_generator()))

Author: SandhyaR | Tags: iterator | 1859+ Python FAQs | Share
inherit | creating-custom-modules | joining-and-merging-dataframes | handling-missing-values-(fillna,-dropna) | shallow-copy | return-statement | statement | deep-copy | sum-function | list | stack | working-with-binary-files-(rb,-wb) | string-manipulation | thread-safe-data-structures-(queue.queue) | control-flow | installation | data-type | copy | tuple | walking-through-directories-using-os.walk() | test-discovery | advanced-file-operations | lambda | zip | with-statement | writing:-write(),-writelines() | numeric | list-method | multiprocessing | dictionary | math-copysign | version | lambda-function | __future__ | min-max-function | string-methods | loop | string-iteration | library | print | sorted | math | input-function | recursion | arbitrary-arguments-(*args,-**kwargs) | syntax-error | destructor | max-min | loop-control-statements | package-management | sum() | string-slicing | iterable | directory-operations | constructor | python-syntax-and-structure | input | complex | def | complex-number | mysql | anchors-(^,-$) | while-else-loop | syntax-error | using-map()-for-transformations | oop | indentation | opening-files-(open()) | thread-synchronization | generators | operators | string-concatenation | parameter | using-yield-in-functions | integers | center | while-loops | unit-testing | compute | namedtuple | file-handling | __init_subclass__ | command-line-parsing | exception-handling | list-methods-and-slicing | overriding-methods | debugging | postfix | counter | pandas | inheritance | reading-and-writing-files | slicing | async | condition | classes | update | benefit | feature | bitwise-operator | identity-operators-(is,-is-not) | dictionaries | docstring | conditional-statement | virtual-environment | polymorphism | scientific-notation | threading | yield | list-vs-tuple | operator | function-and-scope | methods | sys-module | mapping-function | class-and-inheritance | head-and-tail | oops | arithmetic-operation | formal-and-actual-parameter | enumerate() | assignment-operators | import-method | data-structure | working-with-dates-and-times | overflow | list-join | while-loop | random | factorial-function | string-method | keyword | basic | indexing:-loc-vs-iloc | logical-operators | dicts | expression | quantifiers-(*,-+,-?,-{}) | global-variable | why-use-multiprocessing-over-threading?-(gil) | application | filter | typeerror | __all__-attribute | list-comprehension | error-handling | indexing | zip-function | default-mutable-argument | reading-and-writing-large-files-efficiently | else | escape-operator | class-decorators | list-comprehensions | parsing-with-strptime | floating-point-precision | tuples | string-formatting | control-statement | string | list,-set,-and-dictionary-comprehensions | data-structures | raise-statement | tuple-methods | working-with-file-paths | python-module | list-mutation | mutable | name-mangling | min-function | lists | type_conversion | descriptors | nested-loop | precedence | odd-number | range | append | while-and-for-loop | call | matplotlib | generator | using-else-and-finally | iterator | memory-management | virtual-environment | objects | mathematics | data_structure | print-statement | regex | method | python-repl | python_version | boolean-and-non-boolean | type-conversion | goto-function | integer | variable | object-attribute | using-assertions-(assertequal,-assertraises) | comparison | turtle | global | multiple-inheritance | match | operator-and | using-the-threading-module | namespace | dictionary-methods | boolean | pseudocode | collections | magic-method | intering | exponentiation | assert | literal-characters-and-special-characters | comprehension | tuple-unpacking | time-series-with-pandas | identifier | single-inheritance | membership-operators-(in,-not-in) | filtering-and-indexing | init | booleans | loop-control | else-statement | creating-and-starting-threads | loops | dataframe-and-series-objects | lambda-functions | collection | syntax | input-function | managing-directories-with-os-and-shutil | version-check | higher-order-function | functional-programming | design-principle | floats | list-comprehension | using-os-and-pathlib-modules | built-in-function | software-design | thread | error-handling | python-operators | introduction-to-multiprocessing | exception | logical-operator | defining-functions | logical-operation | difference-between-threads-and-processes | function-argument | asyncio | touples | python-django | regular-expressions | type-conversion-and-casting | precedence-and-associativity | functions | module | control-flow | sys | gil | numpy | assignment-operator | identity-operator | identity-operator | immutability | list-slicing | using-lists-as-stacks | type-conversion | attribute | global-keyword | interpreter | frozenset | split | string-method | operations | data-structure | list-indexing | asyncio-module | data-structures-in-python | heap-memory | file | file_handling | multithreading | function | exception-handling | formatting-with-strftime | int | using-join()-and-is_alive()-methods | aggregating-data-with-functools.reduce() | data-type-conversions | strings | python | access-modifier | context-manager | invalid-list | matrix | zfill-function | encapsulation | immutable-data-type | map-function | binary | filter-function | regular-expression | arithmetic-expression | conditional-statement | pass | datatype | for | file-handling | global-variable | class-and-object | id-function | join | bitwise-operator | slice | static-method | introduction-to-python | iterators | comment | round-function | list-operation | set | recurssion | binary-operation | pep | reading:-read(),-readline(),-readlines() | operator-overloading | working-with-temporary-files-using-tempfile | decimal | multiple-inheritance | generators-in-python | functional-programming | dictionary-comprehensions | introduction-to-threads | staticmethod | boolean-masking | conditional-statements | class | memory | swapping | python-history | expand-tab | string-formatting | format | implementation | operator-or | encoding | sorting-and-ranking | data-type | round | syntaxerror | raise | sorting | rollback | random-function | fabs-function | operand | pickling--unpickling | lambdas | sets | built-in | mathematical-function | error | key-value-pairs | set-operation | logical-operator | multiple-except-blocks | array | decorator | method-overloading | matrix-list-comprehension | string-slicing | built-in-modules | datetime.date,-datetime.time,-datetime.datetime | counter-function | built-in-function | bitwise | default-arguments | conversion | datetime | choice | class-and-instance-variable | data-types ...