JustCaptain kod-buduschego
a33efd81ebf0db5852b9ec96a0cc46460ae2a4b0
Перейти к файлу
Код
task_4.py
from typing import Self


class BrowserHistory:
    def __init__(self, pages: list[str]) -> None:
        self.pages: list[str] = pages
        self.idx: int = 0

    def __iter__(self) -> Self:
        self.idx = 0
        return self

    def __next__(self) -> str:
        if self.idx == len(self.pages):
            raise StopIteration
        self.idx += 1
        return self.pages[self.idx - 1]


history = BrowserHistory(["google.com", "github.com", "stackoverflow.com"])
print("Первый цикл")
for page in history:
    print(page)

print("Второй цикл")
for page in history:
    print(page)