Wednesday, 13 June 2018

Write a program that accepts a comma separated sequence of words as input and prints the words in a comma-separated sequence after sorting them alphabetically Using Python Programming.

# Write a program that accepts a comma separated sequence of words as input
# and prints the words in a comma-separated sequence after sorting them
# alphabetically

str = input("Enter a comma seprated string : ")

if len(str)>0:
    sstr=""
    wordList = str.split(",")
    wordList = sorted(wordList)
    for w in wordList:
        sstr +=w
        sstr +=","
    sstr = sstr[:-1]
    print("Sorted String : ",sstr)
else:
    print("String is empty.")

input("Press Enter to exit.")

No comments:

Post a Comment

Popular Posts