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