Does python support fixed LIFO size?

I need a data structure, a fixed LIFO size, the last in the first. Is it already there?

Edit: Sorry, I want LIFO, not FIFO.

I checked http://docs.python.org/library/queue.html , it already provides LIFO, the only thing I want to achieve is to automatically abandon the oldest one.

For example) LIFO size 5 with elements: 1 2 3 4 5

After 6 enters, 1 should be discarded, it becomes:

2 3 4 5 6

How can I do that?

+3
source share
1 answer

Both collections.deque and queue.Queue support fifo and maximum size.

+8
source

Source: https://habr.com/ru/post/1779315/


All Articles