diff --git a/shared/notes-and-examples/2026.03.04/dictionary.py b/shared/notes-and-examples/2026.03.04/dictionary.py new file mode 100644 index 0000000..d3be4c4 --- /dev/null +++ b/shared/notes-and-examples/2026.03.04/dictionary.py @@ -0,0 +1,20 @@ +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")) + diff --git a/shared/notes-and-examples/2026.03.04/homework.py b/shared/notes-and-examples/2026.03.04/homework.py new file mode 100644 index 0000000..1df6226 --- /dev/null +++ b/shared/notes-and-examples/2026.03.04/homework.py @@ -0,0 +1,7 @@ +# Homework: +# Make the Dictionary class work for any length string. Use any method you can think of. + +# The following should work: +# sample_dict = Dictionary() +# sample_dict.set("test string", "test value") +# sample_dict.set("foo", "bar")