Python Datatype for a fixed-length FIFO

前端 未结 3 1922
孤城傲影
孤城傲影 2020-12-13 08:14

I would like to know if there is a native datatype in Python that acts like a fixed-length FIFO buffer. For example, I want do create a length-5 FIFO buffer that is initial

3条回答
  •  时光取名叫无心
    2020-12-13 09:07

    you can also use list

    a = [0,0,0,0,0]
    
    a.pop(0)
    a.append(1)
    
    print a
    result [0,0,0,0,1]
    

    or for left side in right out, otherwise

    a.pop(5)
    a.insert(0,1)
    print a
    result [1,0,0,0,0]
    

提交回复
热议问题