I have a list of values like this,
lst = [1, 2, 3, 4, 5, 6, 7, 8]
Desired Output:
window size = 3
1 # first element in the list
forward = [2, 3, 4]
backward = []
2 # second element in the list
forward = [3, 4, 5]
backward = [1]
3 # third element in the list
forward = [4, 5, 6]
backward = [1, 2]
4 # fourth element in the list
forward = [5, 6, 7]
backward = [1, 2, 3]
5 # fifth element in the list
forward = [6, 7, 8]
backward = [2, 3, 4]
6 # sixth element in the list
forward = [7, 8]
backward = [3, 4, 5]
7 # seventh element in the list
forward = [8]
backward = [4, 5, 6]
8 # eight element in the list
forward = []
backward = [5, 6, 7]
Lets assume a window size of 4, now my desired output:
for each_element in the list, I want 4 values in-front and 4 values backward ignoring the current value.
I was able to use this to get sliding window of values but this also not giving me the correct required output.
import more_itertools
list(more_itertools.windowed([1, 2, 3, 4, 5, 6, 7, 8], n=3))