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