sentence = input("Enter a sentence: ")
# Split the sentence into a list of words
words = sentence.split()
# Sort the list of words by length (in ascending order)
words.sort(key=len)
# Print the sorted list of words
print(words)
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
sentence = input("Enter a sentence: ")
# Split the sentence into a list of words
words = sentence.split()
# Sort the list of words by length (in ascending order)
words.sort(key=len)
# Print the sorted list of words
print(words)