A ring buffer keeps the last N items in a fixed-size list, overwriting the oldest when full: ideal for "last 100 log lines" or a rolling metric window.
Implement a class RingBuffer(capacity) backed by a preallocated list (don't use collections.deque):
append(x), len(buf), buf.is_full()buf[i], where 0 is the oldest item and negative indices count from the newest. Out of range raises IndexError.to_list()mean(): the average of the current items, kept in O(1) per append with a running sum (ValueError if empty)