How to extract the longest words alphabetically in a text in Python?

I have a problem as I am a total beginner to Python, now learning text-manipulation. I am trying to extract the five longest words in a text, create a list with those items and order them alphabetically. Then I need to print the results.
How do I proceed?

1 answer

  • answered 2021-09-23 11:33 king juno

    strings = input("Enter a Text: ").split() # split the text into a list of words
    sorted_list = list(sorted(strings, key = len,reverse=True))[:5] # sort the list by length of the words
    ans = sorted(sorted_list) # sort the list alphabetically
    print(ans)  # print the list
    

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum