slicing

Taking a sub-sequence of a list, string or tuple with the syntax seq[start:stop], which in Python returns a new copy.

In more detail

A list slice copies every element reference in the range, so it costs O(k) time and memory for k elements. Changing the slice afterwards does not change the original list. Code that slices inside a loop, such as recursive helpers that pass lists[1:], quietly adds linear cost at every step.

Related terms

Taught in

References