程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

The use of hash table and set in python

編輯:Python

The hash table cannot use mutable objects as the key value, that is, the content of the reference type cannot be mutable, which is unsafe, because the hashcode function calculates the position of the key and value according to the content of the object, if the content of the referenceIf it is variable, the result of each search will be different, and the previously stored key-value pairs will not be found, which does not conform to the design principles of hash. For example, the list type is variable, and the tuple is immutable

The hash table inserts and deletes elements as shown in the figure above, and the output is as follows:

set:
The bottom layer of set is a specialThe value of the hashmap corresponds to the key in the key-value pair, so it cannot store mutable objects.
The establishment of set needs to be passed in in the form of a list, and can also be added directly through the add method:

Result:


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved