Guest User

Untitled

a guest
Jan 18th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. import string
  2. cryptogram = "gfmncwmsbgblrrpylqjyrcgrzwfylbrfyrq"$#abbreviated version of the cryptogram
  3.  
  4. cryptolist=list(cryptogram)
  5.  
  6. def alpha_num_dic(): #creates dictionary with alphabet assigned nums 1 thru 26
  7. alpha= (string.ascii_lowercase)
  8. alphalist = list(alpha)
  9. numrange=range (1,27)
  10. alphadict = dict(zip(alphalist,numrange))
  11. return alphadict
  12.  
  13. def dictionary(y): #cryptolist passed in
  14. dictlist = []
  15. b=alpha_num_dic()
  16. for item in y: #loop cryptolist
  17. getkey=b[item] #each cryptolist item is the key for a lookup
  18. dictlist.append(getkey) #assign value to dictlist
  19. conversion(dictlist,alpha_num_dic)
  20.  
  21. def conversion(z,dictionary):
  22. newnum=[]
  23. for value in z:
  24. if value < 25:
  25. value += 2
  26. elif value == 25:
  27. value = 1
  28. elif value == 26:
  29. value = 2
  30. newnum.append(value)
  31. reverse_lookup(dictionary,newnum)
  32.  
  33. #works up til here. I can't figure out how to iterate through a dictionary.
  34. def reverse_lookup (dictionary,newnum):
  35. for item in dictionary: #for passed value in dictionary
  36. if dictionary[item] == newnum: # if dict[value] ==
  37. print item
  38.  
  39. dictionary(cryptolist)
Add Comment
Please, Sign In to add comment