fork download
  1. lst = [1,2,3,4,5,6,7,8]
  2. def sliding_window(elements, window_size):
  3. lst2 = []
  4. for i in range(len(elements)-window_size):
  5. a = sum(elements[i:i+window_size])/window_size
  6. lst2.append(a)
  7. return lst2
  8.  
  9. lst2 = sliding_window(lst, 3)
  10.  
  11. print(lst2)
Success #stdin #stdout 0.11s 14116KB
stdin
Standard input is empty
stdout
[2.0, 3.0, 4.0, 5.0, 6.0]