Day 19 of 100 Days of Python
Practising DSA
First Program:
1
2
3
4
5
6
7
8
9
underlying_array_size = 10;
user_keys = ["alpha", "beta", "gamma", "delta"];
for key in user_keys:
s=0
for i in key:
s = s+ ord(i)
ti = s%underlying_array_size
print(f"Key '{key}' maps to array index: {ti}")
Output:
1
2
3
4
Key 'alpha' maps to array index: 8
Key 'beta' maps to array index: 2
Key 'gamma' maps to array index: 5
Key 'delta' maps to array index: 2
This post is licensed under CC BY 4.0 by the author.