Level 3 : What does this iterator return?


class StepSkipIterator:
    def __init__(self, data, step):
        self.data = data
        self.step = step
        self.index = 0

    def __iter__(self):
        return self

    def __next__(self):
        if self.index >= len(self.data):
            raise StopIteration
        val = self.data[self.index]
        self.index += self.step
        return val

it = StepSkipIterator("Python", 2)
print(list(it))

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