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