Python overwriting and resizing list
<p>I want to create a list in python of a fixed size, let's so 3 to begin with. I have a method that writes data to this list every time the method is called, I want to add this to the list until the list is full, once the list is full it should start overwriting the data in the list in ascending order (e.g. starting with element 0). I also want to add a function which will increase the length of the array, i.e. if the method is called the array will increase from size 3 to size 4. How do I go about doing either of these?</p>

<p>This should do the trick. There are tons of prebuilt modules that have similar functionality but I thought it would be best if you could visualize the process!</p>

<pre><code>class SizedList(list):
    def __init__(self, size):
        list().__init__(self)
        self.__size = size
        self.__wrap_location = 0
        self.len = len(self)

    def append(self, *args, **kwargs):
        self.len = len(self)
        if self.len &gt;= self.__size:
            if self.__wrap_location == self.__size-1:
                self.__wrap_location = 0
            self.__wrap_location += 1
            self.pop(self.__wrap_location)
            return self.insert(self.__wrap_location-1, *args)
        return list.append(self, *args, **kwargs)

    def increase_size(self, amount=1):
        self.__size += 1
</code></pre>

python arrays list