Alternative for delete statement

In the function below I only want to use the data after the first 5600 elements in the list, so I delete that in this function, but everytime I call this function it deletes the first 5600 elements of the already shorter list. Is there a way to fix this?

def aardbeving(output,kolom):
    sd = np.std(baseline(output,20*tijdstap(output),kolom),ddof=1)
    
    for i in range(5600):
        del output[0]
        
    verschil = np.diff(channel(output,kolom))
    
    for i in range(len(verschil)):
        if abs(verschil[i]) > 5*sd:
            starttijd = -10 + i/tijdstap(output)
            return starttijd

Rather than deleting the begining of output take a slice of every thing after 5600. This does not change output as short is just a local reference to the data, not a copy.
John

it deletes 5600 elements every time because delete removes the element from the list and you won’t be able to get back the original list once it deletes an element. Rather try slicing like max suggested, however if you alter any element in slice the original list might get affected(unless you are fine with it), I would suggest you create a deep copy of the slice and then operate on it.

First hint for better Python code:

  • You don’t need to delete items one at a time, that is super-slow. Better to delete lots of items all at once: del output[0:5600]

Second hint:

  • Deleting items from a list or array is slow. Better to make a copy of the items you don’t want deleted: new_output = output[5600:]

(Notice the colon : in that.) Then operate on new_output instead of output.

The best part of this is that working with new_output means that the original data in output hasn’t been touched.