Skip to content
Home » Python code to arrange the letters of a word in its alphabetical order

Python code to arrange the letters of a word in its alphabetical order

Python Code to arrange the letters of a word in its alphabetical order

def arrange(wd):
    p=len(wd)
    word=''
    for i in range(65,91):
        for j in range(0,p):
            ch=wd[j]
            if ch==chr(i) or ch==chr(i+32):
                word=word+ch
    return word
# main program
wd=input("Enter a word:")
wd=wd.lower()
wd1=arrange(wd)
print("Dictionary Order:")
print(wd1)

Output

Enter a word: sunday is a holiday

Dictionary Order:

aaaddhiilnossuyy