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