how to put names in alphabetical order in python code example
Example 1: position in alphabet 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)
Example 2: how to use order in alphabet python
my_str = "Hello this Is an Example With cased letters"
words = my_str.split()
words.sort()
print("The sorted words are:")
for word in words:
print(word)