Question: Write the Python code to count the number of unique words in a given paragraph. The paragraph may contain words with special characters such as


Write the Python code to count the number of unique words in a given paragraph. The paragraph may contain words with special characters such as ?,? ,,and' and digits are not permitted. Special character must occur only at the end of a word in a passage that is Hello world! is valid but Hello World or Hello Wor!ld is invalid. No two special character occur together. Print 'Invalid input' for such cases. Count words without including special characters. Counting must be case insensitive. Print words in lower case and in sorted order in a dictionary. For example, given a passage 'Programming is a skill in demand! Your programming skills are bankable assets.' The output should be {'a': 1, 'are': 1, 'assets': 1, 'bankable': 1, 'demand": 1, 'in': 1, 'is': 1, 'programming': 2, 'skill': 1, 'skills': 1, 'your': 1) [Hint: use pprint function for printing dictionary in sorted order. Syntax for pprint is pprint(dictionary name) Include the line "from pprint import pprint" in the top of your program] Input format: Enter a paragraph Output format: Dictionary of unique words in the paragraph and their count Boundary conditions: The paragraph is entered at a stretch For example: Test Input Result 1 How are you dear? Are you better dear? {'are': 2, "better': 1 4 Hai!! Hai guys Invalid input
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
