Level 1 : Factorial sequence.


import math

class FactorialIterator:
    def __init__(self, n):
        self.n = n
        self.current = 0

    def __iter__(self):
        return self

    def __next__(self):
        if self.current > self.n:
            raise StopIteration
        value = math.factorial(self.current)
        self.current += 1
        return value

it = iter(FactorialIterator(4))
print(list(it))

Author: SandhyaR | Tags: iterator | 1736+ Python FAQs | Share
functional-programming | debugging | matplotlib | counter-function | random | built-in-function | identity-operator | operator | encoding | input-function | import-method | global-variable | mutable | python_version | list-comprehension | syntaxerror | library | dictionaries | asyncio-module | design-principle | string-manipulation | split | format | context-manager | loop | polymorphism | math | mathematical-function | filter | turtle | iterable | indentation | expression | dictionary | comprehension | operator-overloading | built-in | list-operation | random-function | string-iteration | fabs-function | touples | asyncio | list-comprehension | data-structures | python-repl | python-history | keyword | round-function | slice | math-copysign | file_handling | enumerate() | heap-memory | list | int | version-check | function-and-scope | append | virtual-environment | lambda | statement | logical-operator | min-function | choice | virtual-environment | input | matrix | multiprocessing | syntax-error | loop-control | decorator | inheritance | exception | bitwise-operator | while-else-loop | python | list-join | regex | list-slicing | application | odd-number | tuple-unpacking | formal-and-actual-parameter | inherit | classes | zip | installation | copy | exponentiation | comparison | package-management | init | class-and-object | numeric | staticmethod | matrix-list-comprehension | feature | memory-management | oop | assignment-operator | decimal | software-design | __all__-attribute | type_conversion | exception-handling | string-method | raise | file-handling | pep | thread | file | threading | round | gil | immutability | data-structure | list-method | string | tuple | logical-operator | data-structure | lambda-function | set | sys-module | operators | frozenset | loops | recurssion | default-mutable-argument | higher-order-function | __future__ | precedence-and-associativity | assert | global-keyword | functions | zip-function | constructor | attribute | integer | version | object-attribute | center | pandas | command-line-parsing | multithreading | while-and-for-loop | file-handling | typeerror | condition | print-statement | control-statement | lambdas | multiple-inheritance | call | string-formatting | built-in-function | error-handling | print | function-argument | head-and-tail | arithmetic-operation | string-formatting | collection | docstring | logical-operation | benefit | id-function | with-statement | error | operand | goto-function | operator-and | min-max-function | join | control-flow | syntax-error | indexing | match | basic | conversion | max-min | shallow-copy | sum() | nested-loop | filter-function | list-vs-tuple | control-flow | complex-number | floating-point-precision | bitwise | exception-handling | recursion | function | counter | mysql | pickling-&-unpickling | immutable-data-type | dicts | boolean | boolean-and-non-boolean | compute | sorting | data_structure | operations | variable | string-method | python-module | bitwise-operator | map-function | operator-or | string-slicing | methods | memory | array | class-and-inheritance | escape-operator | python-django | update | name-mangling | identity-operator | identifier | collections | oops | conditional-statement | string-slicing | encapsulation | mathematics | sum-function | else-statement | factorial-function | rollback | zfill-function | method | static-method | sorted | parameter | scientific-notation | invalid-list | while-loop | syntax | deep-copy | implementation | overflow | __init_subclass__ | namedtuple | module | list-indexing | datatype | global-variable | conditional-statement | global | set-operation | binary-operation | expand-tab | binary | return-statement | slicing | generators | complex | datetime | objects | async | sys | generator | swapping | lists | regular-expression | access-modifier | postfix | type-conversion | numpy | for | mapping-function | destructor | iterator | comment | namespace | yield | input-function | class-and-instance-variable | interpreter | arithmetic-expression | type-conversion | precedence | stack | generators-in-python | descriptors | data-type | list-mutation | string-concatenation | pseudocode | magic-method | data-type | range | class | def ...