Python Practice › Collections Programs › Program 9
Stack with deque
Write a Python program that uses a deque as a last-in, first-out stack.
Output
back to product -> search
Approach
appendandpopfrom the same end.
Solution
from collections import deque history = deque()for page in ["home", "search", "product"]: history.append(page)print("back to", history.pop(), "->", history[-1])Output
back to product -> search
Learn the concept
New to this topic? Read the lesson, then come back.