Advertisement
here2share

# num2alpha.py vs infiniteshakespearianmonkey

Aug 7th, 2015
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. # num2alpha.py -- demo vs infiniteshakespearianmonkey ;)
  2. subatomic = 'abcdefghijklmnopqrstuvwxyz_' # "_" represents other key elements
  3.  
  4. def num2alpha(num):
  5.     letters = ''
  6.     while num:
  7.         mod = (num - 1) % 27 #26
  8.         letters += subatomic[mod] # or... chr(mod + 65).lower()
  9.         num = (num - 1) // 27 #26
  10.     return ''.join(reversed(letters))
  11. #
  12.  
  13. result = ''
  14. count = 1
  15. while result != 'bye' and len(result) < 19: # or True (as pseudo infinite)
  16.     result = num2alpha(count)
  17.     print result,
  18.     count += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement