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