Getting a slice is O(i_2 - i_1
). This is because Python’s internal representation of a list is an array, so you can start at i_1
and iterate to i_2
.
For more information, see the Python Time Complexity wiki entry
You can also look at the implementation in the CPython source if you want to.