Internal working of list in Python Last Updated : 09 Dec, 2021 Comments Improve Suggest changes Like Article Like Report Introduction to Python lists : Python lists are internally represented as arrays. The idea used is similar to implementation of vectors in C++ or ArrayList in Java. The costly operations are inserting and deleting items near the beginning (as everything has to be moved). Insert at the end also becomes costly if preallocated space becomes full.We can create a list in python as shown below.Example: Python3 list1 = [1, 2, 3, 4] We can access each element of a list in python by their assigned index. In python starting index of list sequence is 0 and ending index is (if N elements are there) N-1. Also as shown in above array lists also have negative index starting from -N (if N elements in the list) till -1.Viewing the elements of List in Python : Individual items of a list can be accessed through their indexes as done in below code segment. Python3 list1 = [1, 2, 3, 4] # for printing only one item from a list print(list1[1]) # to print a sequence of item in a list # we use ':' value before this is starting # and value after that tells ending of sequence print(list1[1:4]) # accessing through negative index print(list1[-1]) Assigning and Accessing data: For creating a list we need to specify the elements inside square brackets '[]' and then give it a name. Whenever you want to access the list elements then use this list name and index of element you want to show. Each element in list is assigned an index in positive indexing we have index from 0 to end of the list and in negative indexing we have index from -N(if elements are N) till -1. As shown in above examples the work of accessing elements is manual. We can also access or assign elements through loops. Python3 # assigning elements to list list1 =[] for i in range(0, 11): list1.append(i) # accessing elements from a list for i in range(0, 11): print(list1[i]) Updating list: We can update already assigned elements to the list and also can append one element at a time to your list.Even you can extend your list by adding another list to current list. The above task can be performed as follows. Python3 list1 =[1, 2, 3, 4] # updating list1[2]= 5 print(list1) # appending list1.append(6) print(list1) # extending list1.extend([1, 2, 3]) print(list1) Note: append() and extend() are built in methods in python for lists.Deleting elements of list : We can delete elements in lists by making use of del function. In this you need to specify the position of element that is the index of the element and that element will be deleted from the list and index will be updated. In above shown image the element 3 in index 2 has been deleted and after that index has been updated. Python3 list1 = [1, 2, 3, 4, 5] print(list1) # deleting element del list1[2] print(list1) Time Complexities of Operations OperationAverage CaseAmortized Worst CaseCopyO(n)O(n)Append[1]O(1)O(1)Pop lastO(1)O(1)Pop intermediateO(k)O(k)InsertO(n)O(n)Get ItemO(1)O(1)Set ItemO(1)O(1)Delete ItemO(n)O(n)IterationO(n)O(n)Get SliceO(k)O(k)Del SliceO(n)O(n)Set SliceO(k+n)O(k+n)Extend[1]O(k)O(k)SortO(n log n)O(n log n)MultiplyO(nk)O(nk)x in sO(n)O(n)min(s), max(s)O(n)O(n)Get LengthO(1)O(1) Source : Python WikiPython list and its operations. Comment More infoAdvertise with us Next Article Internal working of list in Python D DikshaTewari Follow Improve Article Tags : Python Practice Tags : python Similar Reads Iterate over a list in Python Python provides several ways to iterate over list. The simplest and the most common way to iterate over a list is to use a for loop. This method allows us to access each element in the list directly.Example: Print all elements in the list one by one using for loop.Pythona = [1, 3, 5, 7, 9] # On each 3 min read How to Find Length of a list in Python The length of a list means the number of elements it contains. In-Built len() function can be used to find the length of an object by passing the object within the parentheses. Here is the Python example to find the length of a list using len().Pythona1 = [10, 50, 30, 40] n = len(a1) print("Size of 2 min read How to Initialize a List in Python Python List is an ordered collections on items, where we can insert, modify and delete the values. Let's first see how to initialize the list in Python with help of different examples. Initialize list using square brackets []Using [] we can initialize an empty list or list with some items. Python# I 2 min read range() to a list in Python In Python, the range() function is used to generate a sequence of numbers. However, it produces a range object, which is an iterable but not a list. If we need to manipulate or access the numbers as a list, we must explicitly convert the range object into a list. For example, given range(1, 5), we m 2 min read How to iterate through list of tuples in Python In Python, a list of tuples is a common data structure used to store paired or grouped data. Iterating through this type of list involves accessing each tuple one by one and sometimes the elements within the tuple. Python provides several efficient and versatile ways to do this. Letâs explore these 2 min read Python List of Lists A list of lists in Python is a collection where each item is another list, allowing for multi-dimensional data storage. We access elements using two indices: one for the outer list and one for the inner list. In this article, we will explain the concept of Lists of Lists in Python, including various 3 min read Python List index() - Find Index of Item index() method in Python is a helpful tool when you want to find the position of a specific item in a list. It works by searching through the list from the beginning and returning the index (position) of the first occurrence of the element you're looking for. Example:Pythona = ["cat", "dog", "tiger" 3 min read llist module in Python Up until a long time Python had no way of executing linked list data structure. It does support list but there were many problems encountered when using them as a concept of the linked list like list are rigid and are not connected by pointers hence take a defined memory space that may even be waste 3 min read Create a List of Tuples in Python The task of creating a list of tuples in Python involves combining or transforming multiple data elements into a sequence of tuples within a list. Tuples are immutable, making them useful when storing fixed pairs or groups of values, while lists offer flexibility for dynamic collections. For example 3 min read Access List Items in Python Accessing elements of a list is a common operation and can be done using different techniques. Below, we explore these methods in order of efficiency and their use cases. Indexing is the simplest and most direct way to access specific items in a list. Every item in a list has an index starting from 2 min read Like