Circular lists python


i’m trying to iterate through a circular list and add the next x values but i need some help

from typing import List

def solution(k: [int], x: int) → [int]:
res =
n = len(k)
for i in range(len(k)):
if x > 0:
j = k[(i + 1) % len(k)] + k[(i + x) % len(k)] # sum of the next x values
elif x < 0:
j = sum(k[(i+x):i]) # sum of the previous x values
j = 0 # x is zero
return res

if i call solutions with;
solution([1,2,3,4], 2) it works properly,but if call solutions with the x value greater than 2 it won’t work well, i need some help reconstructing the j formular so that my output is the sum of the next x values

Without preserving the original formatting of your code, especially indentation, we have no way to know which lines are included in which code blocks. Please repost your code following the instructions for properly formatting your code for the forums.