Stacking and queuing with lists

Stacks and queues are concepts that describe how items get added to and removed from lists. Stacks and queues are not Python objects, but you can write code in which a list behaves like a stack or a queue.

A stack is like a spring-loaded plate dispenser where the last item on is the first item off (this is also called "last in, first out" order, which is inscribed in the Great Book of Geeky Acronyms as "LIFO"). A queue, as folks familiar with British English know, is like a line at a store checkout counter: The first person in is the first served (also called "first in, first out," or "FIFO").

Was this article helpful?

0 0

Post a comment