Skip to content

Instantly share code, notes, and snippets.

Created Mar 20, 2021
What would you like to do?
class hashtable:
def __init__(self, items):
self.bucket_size = len(items)
self.buckets = [[] for i in range(self.bucket_size)]
def assign_buckets(self, items):
for key, value in elements:
hash_value = hash(key)
index = hash_value % self.bucket_size
self.buckets[index].append((key, value))
def get_value(self, input_keys):
hash_value = hash(input_keys)
index = hash_value % self.bucket_size
bucket = self.buckets[index]
for key, value in bucket:
if key == input_keys:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment