Python Datatype for a fixed-length FIFO

前端 未结 3 1926
孤城傲影
孤城傲影 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-13 08:49

    Just one more example to this post

    from collections import deque
    
    domains = ['1.com','2.com','3.com']
    d = deque(domains)               
    d.pop() #pop(delete) 3.com here
    d.appendleft('new.com') 
    
    
    print d
    

    result:

    deque(['new.com', '1.com', '2.com'])
    

提交回复
热议问题