Created
September 10, 2011 22:03
-
-
Save bensonk/1208858 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HashTable(object): | |
def __init__(self, size=100): | |
self.data = [ list() for x in range(size) ] | |
def add(self, key, item): | |
l = self.data[hash(key)] | |
for i, tup in enumerate(l): | |
if tup[0] == key: | |
del l[i] | |
break | |
self.data[hash(key)].append((key, item)) | |
def get(self, key): | |
for k, v in self.data[hash(key)]: | |
if k == key: | |
return v | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment