String in alphabetical order in python

 # Python program to sort a string in alphabetical order


string = input("Enter the string : ")

j = 0

str1 = ""

temp = 0

str = list(string)


for i in range(0, len(str)):

for j in range(0, len(str)):

if(str[j] > str[i]):

temp = str[i]

str[i] = str[j]

str[j] = temp

print("The sorted string is : ")

print(str1.join(str))


 Output :

Enter the string : edcba
The sorted string is : 
abcde

0 comments:

Post a Comment

gurnoorsingh5974@gmail.com

Count Upper Case and Lower Case Word in a string (Python)

  Count Upper Case and Lower Case Word in a string     (Python) def string_test(s):     d={"UPPER_CASE":0, "LOWER_CASE":...