Question: 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
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. marks
b Create a list named keywordsList which consists of 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. 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. marks
d Iterate through the list and increment the value of the current keyword for the dictionary. marks
e Sort the dictionary based on the count of occurrence of the keyword in descending order. Hint: use python's sorted inbuilt function to sort the dictionary marks
f The expected output is given below: Hint: use ljust function to adjust the spacing for the output marks Keywordname 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.
tableKeywordname,Countprintandbreakdelelsewhilereturnimportincontinuenotdefelifglobaloriffor
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
