#C12986. Word Lengths Dictionary
Word Lengths Dictionary
Word Lengths Dictionary
You are given a string containing words, punctuation, and spaces. Your task is to extract all words with at least 3 characters after removing all punctuation and converting all letters to lowercase. Then, for each such word, determine its length. Finally, output a dictionary (in Python literal format) where each key is the word and the corresponding value is the word's length. The dictionary should list the key-value pairs in lexicographical order of the keys.
For example, given the input "Hello, world!", after processing the text becomes "hello world" and the output should be {'hello': 5, 'world': 5}
.
Note: The output must exactly match the required format, including the use of single quotes around keys, the colon and space separators, and the comma-space separation between pairs. If no word meets the criteria, output an empty dictionary: {}.
In mathematical terms, if S is the set of words in the processed string such that \( |w| \ge 3 \) (where \(|w|\) denotes the length of the word), then the output is:
\[ \{ 'w' : |w| \;\text{ for }\; w \in S \} \]inputFormat
The input consists of a single string provided via standard input. The string may contain letters, punctuation, and spaces.
outputFormat
Output the dictionary in a single line using Python dictionary literal format. The dictionary keys (words) should be enclosed in single quotes and listed in lexicographical order. Each key-value pair should be formatted as 'word': length
, and pairs should be separated by a comma and a space. If there is no valid word, output {}.
Hello world
{'hello': 5, 'world': 5}