int to alphabet letter python 1

int to alphabet letter python

from string import ascii_lowercase


LETTERS = {letter: str(index) for index, letter in enumerate(ascii_lowercase, start=1)} 

def alphabet_position(text):
    text = text.lower()

    numbers = [LETTERS[character] for character in text if character in LETTERS]

    return ' '.join(numbers)

Here is what the above code is Doing:
1. Create a dictionary with the letters of the alphabet as keys and their position in the alphabet as values.
2. Create a list of the numbers that correspond to the letters in the text.
3. Join the numbers with spaces and return the result.

Similar Posts