I want to generate contiguous sliding window from a list
nums = [1,2,3,4,10]
####O/P
[[1, 2], [2, 3], [3, 4], [4, 10]]
My code so far -
>>> num_list = [1,2,3,4,10]
>>>
>>> res = []
>>> n = len(num_list)
>>>
>>> for i in range(n):
... imm = []
... for j in range(i,i+1):
... imm += [num_list[i], num_list[j]]
... res += [imm]
...
>>> res
[[1, 1], [2, 2], [3, 3], [4, 4], [10, 10]]
I m beginner in python , the num_list
is a just fraction of the actual list, its longer