Python dictionary Some in-depth experience
Python dictionary 3 methods, items (), values (), keys (), returned object not list,3 methods The returned object can be iterated, and the dictionary can be deduced
squares={number:number**2 for number in range(100)}
CPython's dictionary uses a hash table as the underlying data structure, only the hash object can be used as a dictionary key, the hash object is the entire invariant object, and can be compared with other objects, if an object has __hash__
methods, __eq__
properties, is hash.
If two objects are equal, then their hash values must be equal, if the two hash values are equal, then the object is not necessarily equal, the simple way of understanding is that 1 and 6 modulo 5 results are 1, the hash value is like 1, the object is 1,6. This is a hash conflict. CPython solve this conflict by open addressing method, which is when the conflict occurs, the hash value is stored in the hash table as an empty hash address.
Dictionary copy exists with a shallow copy and a deep copy, a shallow copy copies only a first-level directory, and a deep copy copies all directories
a={1:{‘a‘,‘b‘}}
浅拷贝的情况下,去到键1的值,值是和对象a共享的,操做的时候a里的值也会改变,深拷贝就是将所有的内容都可以复制一边
b=a.copy()浅拷贝
form copy import deepcopy深拷贝
c=deepcopy(a)
Some in-depth experience of Python dictionary