Python

Write an awesome doc for Python. A very nice an practical one extracted from Python official documentation.

View on GitHub

Generators

[!NOTE]

Generators when terminating, automatically raise StopIteration.

next

from typing import Iterator


def reverse(data: str) -> Iterator[str]:
    for index in range(len(data)-1, -1, -1):
        yield data[index]

for char in reverse('golf'):
    print(char)

Generator Expressions

print(sum(i*i for i in range(10)))

YouTube/Aparat