from collections import deque obj = deque([None]*16) for i in range(len(obj)): obj.rotate(-1) obj.rotate(1) obj.count(1)