我对这两个函数感到好奇,这两个函数是最佳的,您将分别分配给哪个大O表示法类别,为什么?
def __getitem__(self, search_key):
for key, value in self.items():
if key == search_key:
return value
raise KeyError('key {} not found'.format(search_key))
def __getitem__(self, key):
if key in self.keys():
return self.values()[self.keys().index(key)]
else:
raise KeyError('key {} not found'.format(key))