Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. W = ['']
  2.  
  3.  
  4. def GetHash(algo):
  5. return int((str(hash(algo)))[0:3])
  6.  
  7. def AdicionaNoDicionario(H, nome):
  8. tamanho = (len(H))
  9. cont = 0
  10. if tamanho == 0:
  11. aux = [GetHash(nome),nome]
  12. H.append(aux)
  13. return H
  14.  
  15. for i in range(len(H)):
  16.  
  17. if GetHash(nome) == H[i][0]:
  18.  
  19. if type(H[i][1]) != list:
  20.  
  21. name = H[i][1]
  22. H[i][1] = []
  23. H[i][1].append(name)
  24. H[i][1].append(nome)
  25. return H
  26.  
  27. else:
  28. H[i][1].append(nome)
  29. return H
  30.  
  31. aux = [GetHash(nome), nome]
  32. H.append(aux)
  33. return H
  34.  
  35.  
  36.  
  37. def ProcuraNoDicionario(d, nome):
  38.  
  39. for i in range(len(d)):
  40. if type(d[i][1]) == list:
  41. try:
  42. for j in range(len(d[i][1])):
  43. if d[i][1][j] == nome:
  44. print "Tem no dicionario"
  45. return nome
  46. except ValueError:
  47. print "Nao tem no dicionario"
  48. break
  49. else:
  50. if d[i][1] == nome:
  51. print "Tem no dicionario"
  52. return d[i][1]
  53. print "Nao tem no dicionario"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement