import string alphamap = dict((c,m + 1) for m,c in enumerate(string.lowercase)) nummap = dict((m + 1,c) for m,c in enumerate(string.lowercase)) def encnum(texto): # Make it lowercase texto = texto.lower() # Iterate through a-z for l in alphamap.keys(): # replace a-z with 1-26 texto = texto.replace(l, " " + str(alphamap[l])) return texto print encnum("abcdef") # Output is 1 2 3 4 5 6