Time complexity for sublists in Python

In Python, what is the time complexity when we create a sublist from an existing list?

For example, here the data is the name of our existing list, and list1 is our sublist created by the slicing data.

data = [1,2,3,4,5,6..100,...1000....,10^6] 
list1 = data[101:10^6]

What is the start time for creating list1?

Is it O(10^6) i.e.O(N), or O(1)?
+4
source share
1 answer

Getting a snippet of a list in python O(M - N)/O(10^6 - 101)

Here you can check the time complexity of python list operations

At the bottom, python lists are represented as arrays. So you can iterate over from some index (N) and stop at another (M)

+7
source

Source: https://habr.com/ru/post/1653723/


All Articles