Files
homelab-dsa-tutoring/shared/notes-and-examples/2026.03.04/dictionary.py
Brendan Chen b6caeb0130
Some checks failed
Deploy to birb co. production / deploy (push) Failing after 6s
Add 2026.03.04
2026-03-04 14:55:42 -08:00

21 lines
461 B
Python

class Dictionary:
backing: "list" = [None] * 26
def hash(self, key: str):
return ord(key) - 97
def get(self, key: str):
index = self.hash(key)
return self.backing[index]
def set(self, key: str, value):
index = self.hash(key)
self.backing[index] = value
sample_dict = Dictionary()
sample_dict.set("h", "hello")
sample_dict.set("i", "hello")
print(sample_dict.get("j"))
print(sample_dict.get("i"))