from typing import Generator

def test_1():
    s = [1, 2, 3, 4, 5]
    d = iter(s)
    print(next(d))
    print(next(d))


def test_2():
    # Выражение-генератор
    b = (i**2 for i in range(1, 6))

    # Обойти можно только один раз
    # Не хранится в памяти
    print(dict(b))
    # print(sum(b))

def test_3():
    weekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
    days = ((i, weekdays[(i + 4)%7]) for i in range(1, 78))
    for _ in range(1, 78):
        print(next(days))

# test_3()

# Функция генератор

def genf():
    s = 7
    for i in range(10):
        yield i  # Замораживает функцию в этом месте
        print(s)
        s = s*10 + 7


def fact(n):
    pr = 1
    for i in range(1, n + 1):
        pr = pr*i
        yield pr
    
# for i in fact(10):
#     print(i, end=' ')


# Generator[yield_type, send_type, return_type]

def echo_round() -> Generator[int, float, str]:
    res = yield
    while res:
        res = yield round(res)
    return 'OK'


def gen_squares(n):
    for i in range(1, n + 1):
        yield i**2

# for i in gen_squares(5):
#     print(i)

def gen_fibonacci_numbers(n):
    first = 0
    second = 1
    for i in range(0, n):
        s = first + second
        second = first
        first = s
        yield s
    
# for i in gen_fibonacci_numbers(10):
#     print(i)

def my_range_gen(n):
    pass
