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