[Python Queue] Convenient use of Deque

Basic operation image of Queue

image.png

Implementation


from collections import deque

d = deque(maxlen=5)
for i in range(1, 7):
    d.append(i)
    print(d)

output

deque([1], maxlen=5)
deque([1, 2], maxlen=5)
deque([1, 2, 3], maxlen=5)
deque([1, 2, 3, 4], maxlen=5)
deque([1, 2, 3, 4, 5], maxlen=5)  <-Reach maximum size
deque([2, 3, 4, 5, 6], maxlen=5)  <- Enqueue &After dequeue

reference

Recommended Posts

[Python Queue] Convenient use of Deque
Convenient use of ipython
Proper use of Python visualization packages
[Python] Summary of how to use pandas
Implementation module "deque" in queue and Python
[Python2.7] Summary of how to use unittest
How to use "deque" for Python data
Summary of how to use Python list
[Python2.7] Summary of how to use subprocess
[Question] How to use plot_surface of python
Introduction of Python
Python #stack queue
Basics of Python ①
Basics of python ①
Copy of python
Introduction of Python
[Python] How to use two types of type ()
Use multiple versions of python environment with pyenv
Use OpenSeesPy regardless of OS or Python version
Summary of how to use MNIST in Python
python development environment -use of pyenv and virtualenv-
Summary of studying Python to use AWS Lambda
Let's use different versions of SQLite3 from Python3!
Use thingsspeak from python
[Python] Operation of enumerate
Use config.ini in Python
Use fluentd from python
I tried to summarize how to use matplotlib of python
Use dates in Python
Unification of Python environment
Copy of python preferences
Convenient Python methods, etc.
Basics of Python scraping basics
[python] behavior of argmax
Use Valgrind in Python
Use MySQL from Python
Use urlparse.urljoin instead of os.path.join for Python URL joins
Use mecab with Python3
Use LiquidTap Python Client ③
Usage of Python locals ()
the zen of Python
Use DynamoDB with Python
Installation of Python 3.3 rc1
How to use Python Kivy ① ~ Basics of Kv Language ~
Queue processing in Python
Let's use the Python version of the Confluence API module.
Use Python 3.8 with Anaconda
[Python] format methodical use
Use python with docker
Use MySQL from Python
Use LiquidTap Python Client ②
# 4 [python] Basics of functions
Let's use the open data of "Mamebus" in Python
Basic knowledge of Python
Use BigQuery from python.
Sober trivia of python3
Summary of Python arguments
Use profiler in Python
[Python] Use the Face API of Microsoft Cognitive Services
Basics of python: Output
Installation of matplotlib (Python 3.3.2)