#C54. Taco Word Lengths
Taco Word Lengths
Taco Word Lengths
This problem requires you to count the lengths of words in a given string. The input string will contain words separated by spaces and may include punctuation. Your task is to output a JSON object where each key is a lowercase word (with punctuation removed) and its value is the length of that word. For example, processing Hello world!
should produce {"hello":5, "world":5}
.
Words are identified using the regular expression \(\texttt{\b\w+\b}\) in \(\LaTeX\) format. Note that if a word appears multiple times, it should only appear once in the output. The keys in the resulting JSON object must be sorted in alphabetical order.
inputFormat
A single line string is provided via standard input. The string may contain letters, numbers, spaces, and punctuation.
outputFormat
A JSON object is printed to standard output. Each key is a lowercase word (with punctuation removed) and its corresponding value is the length of that word. The keys in the JSON object are sorted in alphabetical order and the object is printed without extra spaces.## sample
Hello world!
{"hello":5,"world":5}