Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Using Python, write a program that takes input keywords from a list to create a dictionary which consists of all the keywords as keys
Using Python, write a program that takes input keywords from a list to create a dictionary which consists of all the keywords as keys and their count of occurrence as values. a) Define a main function and write all the logic inside this function. Do not forget the function call for the main function at the end of the program. [10% marks] b) Create a list named keywords List which consists of 20 python keywords. The list must contain duplicate values as well. Some examples of python keywords are: and del, global, while, for, in else, print, return, import, if elif, break, continue, etc. [20% marks] c) Create an empty dictionary named dictionary. The keywords from the list defined above will represent the keys and their respective count of occurrence will represent the values for the dictionary. [10% marks] d) Iterate through the list and increment the value of the current keyword for the dictionary. [25% marks] e) Sort the dictionary based on the count of occurrence of the keyword in descending order. (Hint: use python's sorted() in-built function to sort the dictionary) [25% marks] f) The expected output is given below: (Hint: use ljust() function to adjust the spacing for the output) [10% marks]. Keyword name is the name of the keyword selected from the list into the dictionary which acts as the key. count is the number of occurrences of the keyword in the list which acts as the value in the dictionary. Keyword_name Count print and 5 break del else while return import in continue not def elif 1443332222222 global 1 or if for
Step by Step Solution
★★★★★
3.47 Rating (163 Votes )
There are 3 Steps involved in it
Step: 1
Heres the Python program def main Create a list of Python keywords keywordslist and as assert async ...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