forked from K-Hacks/HacktoberFest-2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhashing.py
29 lines (24 loc) · 770 Bytes
/
hashing.py
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
import re
def display_hash(hashtable) -> None:
for element in range(len(hashtable)):
print(f"{element}", end=" ")
values = hashtable[element]
for value in values:
print(f"--> {value}", end=" ")
print()
def Hashing(keyvalue) -> int:
return keyvalue % len(HashTable)
def insert(Hashtable, keyvalue, value) -> None:
Hashtable[Hashing(keyvalue)].append(value)
# Do not edit the following code
hash_table_size = int(input())
# Create Hashtable as a list of list.
HashTable = [[] for _ in range(hash_table_size)]
input_data = input()
data = []
for item in re.split('], |].', input_data):
item = item[1:]
data = item.split(', ')
if len(data) > 1:
insert(HashTable, int(data[0]), data[1])
display_hash (HashTable)