Sliding Window Algorithm Python