Python Morsels: Stacks and queues in Python (opens in new tab)
Use a Python list for stack operations (last-in, first-out) and a deque from the collections module for queue operations (first-in, first-out). Table of contents Stacks versus Queues Stacks in Python Queues in Python A deque is a "double-ended queue" Stack-like and queue-like operations Stacks versus Queues In Computer Science, stacks and queues are data structures that are optimized to make it inexpensive to remove either the most recently added item or the least recently added item. A queue...
Read the original article