Some basic concepts of python data structure

the list

List:
The list in python is a built-in data type of python. The data types in the list do not have to be the same. What is
stored in the list is the address of the data, that is, the pointer, not the data.

array: array
array() is a function in the numpy package, and the elements in array are all of the same type

Conversion between list and array array in python
list to array: np.array(a)
array to list: a.tolist()

Hash
Hash, generally translated as hash, hash, or transliterated as hash
Hash Simply speaking, it is to generate a unique fixed-length data by passing any piece of data through a certain algorithm

Hash table hash table
is also called hash table, this data structure provides a mapping relationship between key (key) and value (value). As long as a key is given, the matching value can be found efficiently, and the time complexity is close to O(1).
In different languages, the implementation of the hash function is different. In the python language, the hash table The corresponding collection is called a dictionary (dict)

Hash function Hash Function
Hash function, also known as hash function. It converts an input of any length into a fixed-length output through a hash algorithm, and the output value is called a hash value or message digest. Simply put, it is a function that compresses an input message of any length into a fixed-length message digest

Chart explanation https://www.jb51.net/article/247466.htm

collection set

Disorder: In a set, the status of each element is the same, and the elements are disordered.
Mutuality: In a set, any two elements are considered to be different, that is, each element can only appear One-time
determinism: Given a set, any element is given, the element either belongs to or does not belong to the set, the two must be one of them, no ambiguity is allowed

Disorder is reflected in the fact that the set does not support index operations.
Mutuality is reflected in the fact that there cannot be duplicate elements in the set

The bottom layer of collections in Python uses hash storage

a={1,2,3,3,3}
print(a)        #{1, 2, 3}

a={1,2,3,4}
print(a)        #{1, 2, 3, 4}
print(type(a))  #<class 'set'>

b={1,6,7}
a=a|b
print(a)        #{1, 2, 3, 4, 6, 7}

a={1,2,3,4}
b={1,6,7}
a=a&b
print(a)        #{1}

to be continued

Reference

https://zhuanlan.zhihu.com/p/261636002
https://blog.csdn.net/qq_62789540/article/details/122635578
https://blog.csdn.net/zhuzitop/article/details/108793412
https://blog.csdn.net/qq_59307163/article/details/119277743

Guess you like

Origin blog.csdn.net/weixin_48185819/article/details/127124257