Built-in data structures
- Variable
- List lists
- Byterray
- Dict Dictionary
- Set Set
- Not variable
- Tuple tuples
- bytes
- Constants (Int,str,bool, etc.)
list (recommended index)
The list is equivalent to an orderly queue, which can be understood as an orderly contiguous space in memory, which is indexable , mutable, ordered, linear, and iterative .
Advantages:
Search by index (index), replace element efficiency high time complexity O (1).
Trailing append (append) and trailing (POP) element fast efficiency high Time complexity O (1).
Disadvantages:
Adding or removing elements from the middle makes the overall movement of the list elements inefficient.
Because it is a contiguous space of 1, if a large space is opened, memory space is not enough, it will trigger GC garbage collection.
tuple tuples (recommended use index)
Tuples can be understood in memory as a list, which is indexed, immutable, ordered, linear, and iterative .
Advantages:
The time complexity of finding elements by index is O (1).
Disadvantages:
Tuples are immutable, are read-only, and cannot be modified.
Set Set
Set in memory is scattered, discontinuous, non-indexed, he is going to heavy variable unordered can be iterated hash.
Advantages:
Queries whether elements are in the collection (using hash) time complexity O (1) by numeric values.
add element (add) time complexity O (1)
You can use set operations (and set | , Intersection &, symmetric difference ^, also available <, > subset superset).
Disadvantages:
You cannot use an index, you cannot place an element of the same content, and you cannot put a non-hash element (list,set,dity).
Dity Dictionary
Dity in memory are scattered, discontinuous, will reserve the hash space. The unordered variable iterative key is the de-heavy, hash.
Advantages:
Fast (using hash) time complexity O (1) through numeric queries.
Increase kv to TIME complexity O (1).
Remove the kv pair (pop) time complexity O (1).
Disadvantages:
You cannot use an index, you cannot place an element of the same content, and you cannot put a non-hash element (list,set,dity).
Memory consumption is larger relative to list.
Python built-in data structures