#K37487. Word Cloud Generator
Word Cloud Generator
Word Cloud Generator
You are given a single line of text that may include letters, spaces, and punctuation marks. Your task is to create a word cloud by counting the frequency of each word in the text. A word is defined as a maximal sequence of English alphabetical characters (i.e. a–z or A–Z). All letters should be converted to lowercase. All characters that are not alphabetical (including hyphens, apostrophes, and other punctuation) must be considered as delimiters. Finally, output the word frequencies in a dictionary format where the keys are enclosed in double quotes and sorted in lexicographical order.
Note: If the frequency dictionary is empty, output {}. The output format must exactly match the specification.
For example, given the input:
After beating the eggs, Dana read the next step:
The output should be:
{"after": 1, "beating": 1, "dana": 1, "eggs": 1, "next": 1, "read": 1, "step": 1, "the": 2}
Use the following regular expression for splitting the text into words:
[\.,!\?;:\"'()\s\-]+
All frequency counts should be based on words extracted using the above rule, and the final dictionary should be printed exactly in the format shown.
inputFormat
The input consists of a single line of text read from standard input (stdin).
The text may include letters, spaces, and punctuation. You must process the input to extract words as described.
outputFormat
Output a dictionary (in one line) where each key is a word (in lowercase) and its value is the number of times it appears in the text. The keys must be sorted in lexicographical order. The dictionary should be formatted as follows:
{"word1": count1, "word2": count2, ...}
Make sure there are no extra spaces or newlines in the output.
## sampleAfter beating the eggs, Dana read the next step:
{"after": 1, "beating": 1, "dana": 1, "eggs": 1, "next": 1, "read": 1, "step": 1, "the": 2}