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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started