Level 1 : Reversing a string with a generator.


def reverse_string(s):
    for i in range(len(s) - 1, -1, -1):
        yield s[i]

gen = reverse_string("hello")
print("".join(gen))

Author: SandhyaR | Tags: generator | 1736+ Python FAQs | Share
destructor | logical-operator | loop | dictionary | frozenset | factorial-function | error | with-statement | descriptors | string-iteration | expression | exception | goto-function | pickling-&-unpickling | filter-function | data-structure | head-and-tail | method | data-structure | turtle | list-slicing | escape-operator | input | exception-handling | string-formatting | docstring | sys | namespace | multithreading | random-function | built-in-function | math | call | variable | stack | functions | access-modifier | string-slicing | gil | inherit | memory | raise | complex-number | keyword | built-in-function | memory-management | python-repl | datetime | class-and-object | global-variable | zip | random | list-method | mathematical-function | version | map-function | identity-operator | command-line-parsing | while-loop | format | operator-or | while-else-loop | control-flow | conditional-statement | lists | parameter | type-conversion | immutable-data-type | boolean-and-non-boolean | lambda | magic-method | matrix | append | int | object-attribute | for | inheritance | decorator | multiprocessing | string-formatting | namedtuple | dictionaries | immutability | indexing | fabs-function | rollback | id-function | math-copysign | file-handling | global | decimal | lambdas | generator | shallow-copy | data-type | basic | class-and-inheritance | generators | scientific-notation | zip-function | type-conversion | comparison | static-method | mathematics | class-and-instance-variable | constructor | version-check | global-variable | typeerror | oops | async | update | else-statement | set | benefit | range | match | thread | list-indexing | installation | sum-function | choice | import-method | operator-and | oop | pseudocode | bitwise-operator | return-statement | attribute | error-handling | binary | swapping | lambda-function | identity-operator | join | sorted | string-manipulation | assert | identifier | data_structure | precedence-and-associativity | string | operand | list-vs-tuple | sorting | bitwise | precedence | init | polymorphism | copy | numpy | file | matplotlib | control-flow | function-argument | file-handling | counter-function | list-join | arithmetic-operation | list-operation | syntaxerror | odd-number | logical-operation | dicts | recursion | binary-operation | debugging | conversion | tuple | string-method | tuple-unpacking | input-function | name-mangling | __init_subclass__ | recurssion | min-max-function | split | mysql | slice | methods | staticmethod | implementation | regex | assignment-operator | statement | compute | counter | __all__-attribute | array | virtual-environment | comment | set-operation | deep-copy | module | function-and-scope | function | virtual-environment | encoding | pandas | syntax-error | iterable | context-manager | conditional-statement | operator | exception-handling | mutable | invalid-list | python-module | file_handling | comprehension | nested-loop | feature | syntax | def | print | pep | operators | slicing | zfill-function | complex | python | python-history | arithmetic-expression | data-structures | boolean | min-function | max-min | enumerate() | center | type_conversion | design-principle | __future__ | indentation | control-statement | regular-expression | mapping-function | multiple-inheritance | generators-in-python | bitwise-operator | numeric | postfix | matrix-list-comprehension | expand-tab | python-django | yield | sys-module | threading | list | collections | formal-and-actual-parameter | overflow | string-method | built-in | condition | logical-operator | touples | software-design | python_version | filter | iterator | round-function | datatype | asyncio | classes | integer | round | library | operations | loop-control | input-function | heap-memory | data-type | string-slicing | class | functional-programming | global-keyword | print-statement | encapsulation | application | list-comprehension | asyncio-module | interpreter | string-concatenation | exponentiation | package-management | list-mutation | collection | default-mutable-argument | sum() | loops | list-comprehension | floating-point-precision | syntax-error | operator-overloading | while-and-for-loop | higher-order-function | objects ...