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