filmov
tv
Python - Queue With Maximum Length! (Deque)
![preview_player](https://i.ytimg.com/vi/_XpJgAGlbfI/maxresdefault.jpg)
Показать описание
#Python #Shorts
If you ever want to make sure your queue doesn't have more than N number of elements, you can use "deque" from "collections" and define "maxlen" on it. This way, whenever a new element gets inserted that will exceed the defined "maxlen" value, the queue will get rid of the oldest element and the new element will appear last in the queue (remember, a queue is implemented using FIFO (First In First Out) structure). And that is how you can use a queue with maximum length!
-------------------------------------------------------------------------------------
Links:
If you ever want to make sure your queue doesn't have more than N number of elements, you can use "deque" from "collections" and define "maxlen" on it. This way, whenever a new element gets inserted that will exceed the defined "maxlen" value, the queue will get rid of the oldest element and the new element will appear last in the queue (remember, a queue is implemented using FIFO (First In First Out) structure). And that is how you can use a queue with maximum length!
-------------------------------------------------------------------------------------
Links: