[Solved] How to get a set of words and print in alphabetical order in the output? [closed]


The problem was that only a single word was inputted and the sort method has been invoked on it.

Let’s get multiple words, append them to a list and sort them:

input_words = []

# Get input words
word = input('Please enter word\n')
# As long as word is not "stop"
while word != 'stop':
    # Get new input word
    input_words.append(word)
    # Append to list of words
    word = input('Please enter word\n')

# Sort words
input_words.sort()

# Print sorted list of words
print(input_words)

# Write to file
with open('your_file.txt', 'w') as f:
    for item in input_words:
        f.write("%s\n" % item)

3

solved How to get a set of words and print in alphabetical order in the output? [closed]