My friends, for reprint please indicate the source: blog.csdn.net/jiangjunsho…
Disclaimer: During the teaching of artificial intelligence technology, many students asked me some python related questions, so in order to let students master more extended knowledge and better understand AI technology, I asked my assistant to share this Python series of tutorials, hoping to help you! Since this Python tutorial is not written by me, it is not as funny and boring as my AI teaching. But its knowledge points or say in place, also worth reading! PS: if you don’t understand this article, please read the previous article first. Step by step, you won’t feel difficult to learn a little every day!
Next to lists, dictionaries are probably the most flexible built-in data structure type in Python. If you think of a list as an ordered collection of objects, you can think of a dictionary as an unordered collection. The main difference is that elements in dictionaries are accessed by keys, not by offsets.
As built-in types, dictionaries can replace many search algorithms and data structures that you might have to implement manually in lower-level languages. Indexing a dictionary is a very fast search operation.
Dictionaries are sometimes called associative arrays or hashes. They connect a series of values by keys so that you can use the keys to pull an item out of the dictionary. Just like lists, you can use indexes to get content from dictionaries. But indexes take the form of keys, not relative offsets.
Unlike lists, items stored in dictionaries are not in a particular order.
Like lists, dictionaries can be grown or shortened in place (without making a copy). They can contain any type of object, and they support nesting at any depth (lists, other dictionaries, etc.).
Dictionaries can be modified in place by assigning values to indexes.
Because dictionaries are unordered collections, it is not possible to operate in a fixed order (for example, merge and shard operations).
If a list is an array of object references that supports location reading, a dictionary is an unordered table of object references that supports key reading. Dictionaries are essentially implemented as hash tables (data structures that support fast retrieval) that start small and grow on demand. In addition, Python uses optimized hashing algorithms to find keys, so the search is fast. Like lists, dictionaries store object references (not copies).