Question: Write a function sorted_words(wordlist) that takes a single list-of-words argument wordlist, and returns a sorted list of the words in wordlist where the letters are

Write a function sorted_words(wordlist) that takes a single list-of-words argument wordlist, and returns a sorted list of the words in wordlist where the letters are alphabetically sorted. An example of such a word is door, as there is no letter in the word that has a higher Unicode value than any letter that follows it, whereas cat is not, as c precedes a in the word (hint: the sorted function may come in handy in testing whether the letters in a word are alphabetically sorted or not). For example:

>>> sorted_words(["bet", "abacus", "act", "celebration", "door"]) 
['act', 'bet', 'door'] 
>>> sorted_words(['apples', 'bananas', 'spam']) 
[] 
>>> sorted_words(["aims", "Zip"]) 
['Zip', 'aims'] 

Unicode Values and Case

Recall that sorting is based on Unicode values, and that Z has a lower Unicode value than z. As such:

print('Zip' < 'aims') 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!