/
band
/
TOI
Обзор
Документация
Войти
/
band
/
TOI
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
lections/L05_struct/_stack.py
32 строки
693 B
permCoding
up
09 авг 2026, 10:32
09 авг 2026, 10:32
a39aa2a
Код
Авторство
О чём код?
stack = [] stack.append(1) # [1] stack.append(2) # [1, 2] stack.append(3) # [1, 2, 3] top = stack.pop() # [1, 2] from collections import deque stack = deque() stack.append(1) # 1 stack.append(2) # 1, 2 stack.append(3) # 1, 2, 3 print(list(stack)) # [1, 2, 3] print(stack[-1]) top = stack.pop() # 3 print(list(stack)) # [1, 2] print(len(stack)) while stack: print(stack.pop()) from collections import deque queue = deque() queue.append(1) # встал в очередь queue.append(2) queue.append(3) print(list(queue)) # [1, 2, 3] first = queue.popleft() # 1 ушёл print(len(queue)) # 2 print(list(queue)) # [2, 3] while queue: print(queue.popleft())