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