Level 5 : What will this code output?


def word_length(words):
    for word in words:
        yield len(word)

g = word_length(["hello", "python", "iterator"])
print(sum(g))
print(sum(g))

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