Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
52 lines (41 loc) · 1.05 KB

File metadata and controls

52 lines (41 loc) · 1.05 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import fileinput
class Entry:
def __init__(self, key, value):
self.key = key
self.value = value
class MyHashTable:
def __init__(self, capacity):
self.capacity = capacity
self.list1 = [[]]*capacity
def put(self,k,v):
slot = self.hash(k)
bucket = self.list1[slot]
key_in_bucket = False
for entry in bucket:
if entry.key == k:
entry.value = v
key_in_bucket = True
if key_in_bucket == False:
self.list1[slot].append(Entry(k,v))
def get(self,k):
slot = self.hash(k)
bucket = self.list1[slot]
for entry in bucket:
if entry.key == k:
return entry.value
def hash(self,k):
i = 0
total = 0
while i < len(k):
total = total + ord(k[i])
i = i + 1
return total % self.capacity
if __name__ == "__main__":
hashtable = MyHashTable(100)
for line in fileinput.input():
line = line.strip()
k,v = line.split('=') if '=' in line else (line, None)
if v:
hashtable.put(k,v)
else:
print str(hashtable.get(k)).replace('None','null')
Morty Proxy This is a proxified and sanitized view of the page, visit original site.