/
vasiliy.zalizko
/
IteratorsGeneratorsYield
Обзор
Документация
Войти
/
vasiliy.zalizko
/
IteratorsGeneratorsYield
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Problem 1/main.py
41 строка
1 KB
vasiliy.zalizko
Create: main.py, main.py, main.py, main.py
10 авг 2026, 23:44
Верифицирован
10 авг 2026, 23:44
63d6387
Код
Авторство
О чём код?
class FlatIterator: def __init__(self, list_of_list): self.lists = list_of_list self.current_list_index = 0 self.current_item_index = 0 def __iter__(self): return self def __next__(self): while self.current_list_index < len(self.lists): current_list = self.lists[self.current_list_index] if self.current_item_index < len(current_list): item = current_list[self.current_item_index] self.current_item_index += 1 return item else: self.current_list_index += 1 self.current_item_index = 0 raise StopIteration def test_1(): list_of_lists_1 = [ ['a', 'b', 'c'], ['d', 'e', 'f', 'h', False], [1, 2, None] ] for flat_iterator_item, check_item in zip( FlatIterator(list_of_lists_1), ['a', 'b', 'c', 'd', 'e', 'f', 'h', False, 1, 2, None] ): assert flat_iterator_item == check_item assert list(FlatIterator(list_of_lists_1)) == ['a', 'b', 'c', 'd', 'e', 'f', 'h', False, 1, 2, None] if __name__ == '__main__': test_1()