Remember that the number of elements in the data structure is n
Listing (list)
The list is implemented by the array, and the allocated memory is a contiguous space. Adjust and modify the list elements to return the length of the list, the time complexity of these operations is O (1). The operation time in the head of the list is relatively high, O (n).
For example, in a personal local environment, 100,000 elements were added from the tail and head of the list, respectively, and the former took 10ms and the latter took 2100ms. In order to deal with this problem, Collections.deque can be used in particular. This double-ended queue is implemented by a doubly linked list, and the time complexity of deleting and inserting elements in the left and right two segments is O (1)
Dictionary (dict)
The basic implementation of a dictionary is mapped with a hash function. The time complexity of getting, deleting, adding Elements is O (1), the in operation is usually O (1), and the time complexity of O (n) occurs only when the hash function is set unreasonably and a large number of key-value mappings collide, and this is rarely the case.
Time complexity of the python infrastructure