Queue processing in Python

A cue is the first thing you put in and the first thing you put out. (= first in first out) It is realized by python.

# -*- coding: utf-8 -*-

class Queue(object):

    def __init__(self):
        self.queue_list = []

    def enqueue(self, value):
        self.queue_list.append(value)

    def dequeue(self):
        try:
            #Extract the beginning
            value = self.queue_list.pop(0)
        except IndexError:
            value = None

        return value

if __name__ == '__main__':
    queue = Queue()

    queue.enqueue("a")
    queue.enqueue("b")
    queue.enqueue("c")

    print queue.dequeue()
    print queue.dequeue()
    print queue.dequeue()
    print queue.dequeue()

Execution result % python queue.py a b c None

Recommended Posts

Queue processing in Python
File processing in Python
Multithreaded processing in python
Text processing in Python
UTF8 text processing in python
Asynchronous processing (threading) in python
Stack and Queue in Python
Image Processing Collection in Python
Using Python mode in Processing
Signal processing in Python (1): Fourier transform
100 Language Processing Knock Chapter 1 in Python
I wrote the queue in Python
Quadtree in Python --2
Python in optimization
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
python image processing
Meta-analysis in Python
Unittest in python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
Python file processing
quicksort in python
N-Gram in Python
Programming in python
Plink in Python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
nCr in Python.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Asynchronous processing using LINE BOT: RQ (Redis Queue) in Python
Quad-tree in Python
Reflection in Python
Chemistry in Python
Hashable in python
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
flatten in python
Ant book in python: Priority queue self-implementation
Asynchronous processing using Linebot in Job queue
Implementation module "deque" in queue and Python
Easy image processing in Python with Pillow