class Ring_buffer: """manages a list in a ring buffer like manner """ def __init__(self, size: int): """initializes the ring buffer Args: size (int): the size of the ring buffer """ self.size = size self.data = [] def append(self, data): """appends an element to the ring buffer Args: data ([type]): the element to be added """ self.data.append(data) if len(self.data) == self.size: self.data.pop(0) def __str__(self) -> str: """string conversion method for the ring buffer Returns: str: the content of the ring buffer as a string (JSON style) """ return_str = str(self.data) return return_str