def __init__(self, size):
"""
Initialize your data structure here.
:type size: int
"""
self.size = size
self.a = []
def next(self, val):
"""
:type val: int
:rtype: float
"""
if len(self.a) == self.size:
self.a = self.a[1:]
self.a += [val]
return sum(self.a)/float(len(self.a))
python solution

@Helly0000
Yeah, deque is better for this problem. Thanks for your suggestion !
Since there are already some deque solutions, I will leave my solution as it is.