Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@benkoshy 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