pythonarraysmatrixcircular-buffer

How do I implement a circular buffer in Python?


I have a matrix for instance

a=[12,2,4,67,8,9,23]

and I would like a code that appends a value say 45 to it and removes the first value '12' so in essence I want to make

a = [2,4,67,8,9,23,45]

I want to work with regular matrices not numpy matrices so I can't use hstack or vstack How do I do this in python? Any help would be appreciated, thanks


Solution

  • The simplest way:

    a = a[1:] + [45]