I'm a fair beginner in Python and I do understand what is wrong in this case, `SetVel[i+4]` takes it beyond the range. But I can't get my head around rectifying it. Any help would be amazing. Here's my code:

```
OutSmooth = []
IndexOut = []
IndSmooth = []
length = len(SetVel)
for i in range(2, length-3):
    diffnext = (SetVel[i+4])- (SetVel[i+3])
    diffprev = (SetVel[i+1])-(SetVel[i])
    diff1 = SetVel[i+2]-SetVel[i+1]
    diff2 = SetVel[i+3]-SetVel[i+2]
    if diff1 < 1.5*diffprev or diff2 < 1.5*diffnext:
        IndSmooth.append(SetVel.index(SetVel[i+2]))
    else:
        OutSmooth.append(SetVel[i+2])

```

PS: for those asking about what this actually is: It is my attempt at non-derivative curve smoothing. In my main program I do have a NumPy based derivative curve smoothing mechanism, but I have done this for my understanding and as a backup. Thanks

EDIT: 

`break` after the condition worked to remove the error, but the code only runs the block once. Only one index is appended