How to implement the bottom layer of python dictionary type
This article is about how the underlying implementation of python dictionary types is implemented. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
1. The underlying dictionary type is based on a hash table.
2. The data types of keys in the dictionary must be static data types, such as simple data types, strings, and tuples. Dictionary types are data structures based on hash tables.
Example
#-*-coding: utf-8-*-"@ Time: 2021-8-14 21:04@Author: LYP@FileName: dic_Python.py@SoftWare: PyCharm" dict2 = {'abc': 123,98.6: 37} scores = {' Mathematics': 95, 'English': 92, 'Chinese': 84, 'Chemistry': 90, 'Biology': 91 Physics: 80} dic= {} dic [1] = 'hello'dic [2] =' world'#print (dic) # print (dict2) # print (scores) print ("scores ['Mathematics]:", scores [' Mathematics]) print ("scores ['English]:", scores [' English]) print ("scores [Chemistry]:", scores.get ("Chemistry") print ("scores ['Biology]:" Scores.get ('biology') print (scores) for key,value in scores.items (): print (key, "- >", value) print ("add values to the dictionary") scores ['history'] = 80print (scores) scores.setdefault ('geography') 89) print (scores) print ("Delete elements") del scores ['Geography'] print (scores) scores.pop ('History') print (scores) # scores.clear () # print (scores) print ("modify value") print (scores) scores ['Mathematics'] = 100print (scores) print ("determine whether a key-value pair is included in a dictionary") print ("whether scores includes mathematics", "Mathematics'in scores) print (" whether geography is included in scores " Geographic in scores) print ("whether history is included in scores", "history" not in scores) print (scores.keys ()) print (scores.values ()) print (scores.items ()) Thank you for reading! This is the end of this article on "how to realize the bottom of python dictionary type". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!