Python 中集合、映射与树的深入解析
1. 映射(Maps)
映射在编程中是一种非常重要的数据结构,它提供了键值对的存储方式,方便我们根据键快速查找对应的值。在 Python 里,我们可以借助哈希集合(HashSet)来实现哈希映射(HashMap)。以下是具体的实现代码:
class HashMap:
class __KVPair:
def __init__(self, key, value):
self.key = key
self.value = value
def __eq__(self, other):
if type(self) != type(other):
return False
return self.key == other.key
def getKey(self):
return self.key
def getValue(self):
return self.value
def __hash__(self):
return hash(self.key)
def __init__(self):
self.hSet = hashset.HashSet()
def __len__(self):
return len(self.hSet)
def __contain
Python 数据结构详解:集合、映射与树
超级会员免费看
订阅专栏 解锁全文
919

被折叠的 条评论
为什么被折叠?



