Alexander_Smirnov

Untitled

Nov 17th, 2024
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. mass = [[[None],[None]] for _ in range(10)]
  2.  
  3. def to_hash(x):      
  4.     res = [bin(ord(i)) for i in x]  
  5.     res = ''.join([i[2:] for i in res])  
  6.     x = int(res, 2) % len(mass)  
  7.     return x
  8.  
  9. def add_after(ind, val):
  10.     global mass
  11.     i = len(mass[ind][0]) - 1
  12.     mass[ind][0] += [val]
  13.     mass[ind][1] += [mass[ind][1][i]]
  14.     mass[ind][1][i] = len(mass[ind][0]) - 1
  15.  
  16.  
  17. add_after(to_hash('Bill'), 'Bill:Clinton')
  18. add_after(to_hash('Ronald'), 'Ronald:Reagan')
  19. add_after(to_hash('John'), 'John:Fitzgerald Kennedy')
  20. add_after(to_hash('Harry'),  'Harry:S. Truman')
  21. add_after(to_hash('Joe'), 'Joe:Biden')
  22. add_after(to_hash('Jimmy'), 'Jimmy:Carter')
  23. add_after(to_hash('Barack'), 'Barack:Obama')
  24. add_after(to_hash('Theodore'), 'Theodore:Roosevelt')
  25. add_after(to_hash('James'), 'James:Garfield')
  26. add_after(to_hash('Lyndon'), 'Lyndon:Johnson')
  27.  
  28. def find_in_list(name):
  29.     ind = to_hash(name)    
  30.     k = 0    
  31.     while mass[ind][1][k] is not None:        
  32.         #print(mass[ind][0][k + 1])
  33.         result = mass[ind][0][k + 1].split(':')        
  34.         if result[0] == name:
  35.             return result[1]
  36.         k = mass[ind][1][k]
  37.      
  38. print(find_in_list(input('Name of president ').capitalize()))
Advertisement
Add Comment
Please, Sign In to add comment