Python - Queue With Maximum Length! (Deque)

Опубликовано: 23 Октябрь 2024
на канале: codevev
877
25

#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:
Blog: https://evgenyurubkov.com
Twitter:   / evgenyurubkov  
Instagram:   / evgenyurubkov  
Youtube:    / @codevev