Question: Given a Python dictionary that maintians counts of dictinct words occurring in a document: word_count_dict = {'i': 2, 'like': 2, 'business': 3, 'analytics': 2, 'applications':

Given a Python dictionary that maintians counts of dictinct words occurring in a document:

word_count_dict = {'i': 2, 'like': 2, 'business': 3, 'analytics': 2, 'applications': 1, 'development': 2, 'in': 3, 'python': 4, 'is': 3, 'interesting': 1, 'a': 1, 'popular': 1, 'language': 1, 'application': 1, 'hard': 1} 

Use sorted() with a lambda expression to produce the following output:

[('python', 4), ('business', 3), ('in', 3), ('is', 3), ('analytics', 2), ('development', 2), ('i', 2), ('like', 2), ('a', 1), ('application', 1), ('applications', 1), ('hard', 1), ('interesting', 1), ('language', 1), ('popular', 1)]

Note that each dictionary was converted to a 2-element tuple, which represents the word count pair for a distinct word. All word-count pairs were sorted first by count in descending order and then by word in ascending order.

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!