Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

4th Edition

0615231047, 978-0615231044

More Books

Students also viewed these Databases questions

Question

Dont off er e-mail communication if you arent going to respond.

Answered: 1 week ago

Question

=+ Are some laws more important than others? If so, which ones?

Answered: 1 week ago

Question

=+j Describe how EU directives impact IHRM.

Answered: 1 week ago