Skip to content

Instantly share code, notes, and snippets.

@bondnotanymore
Created October 22, 2017 09:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bondnotanymore/e0f1dcaacfb782348e74fac8b224769e to your computer and use it in GitHub Desktop.
Save bondnotanymore/e0f1dcaacfb782348e74fac8b224769e to your computer and use it in GitHub Desktop.
def alphabet_position(text_string):
dict1 = {value: (int(key) + 1) for key, value in enumerate(list(string.ascii_lowercase))}
return " ".join([str(dict1[alp]) for alp in list(text_string.lower()) if alp.isalpha()])
print alphabet_position("The sunset sets at twelve o' clock.")
Output :
"20 8 5 19 21 14 19 5 20 19 5 20 19 1 20 20 23 5 12 22 5 15 3 12 15 3 11"
@benkoshy
Copy link

benkoshy commented Sep 9, 2019

If you come up with the following error:

NameError: name 'string' is not defined

The way to get around it is to import string.

import string

And it should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment