#K79192. Word Lengths
Word Lengths
Word Lengths
Given a string of text, your task is to compute the length of each word after removing any punctuation. The punctuation characters to be removed are defined by the standard ASCII punctuation set \( P = \{!"#$%&'()*+,-./:;?@[\\]^_`{|}~\} \).
When processing the text, remove all punctuation characters from the input. Split the resulting string by whitespace to obtain words. For each word, assign the word (in its original case) as a key and its length (i.e. the number of characters) as the value in the output dictionary.
For example, for the input string "Hello world!", after removing punctuation the words are "Hello" and "world" which gives the dictionary: {"Hello": 5, "world": 5}.
Note: If the same word appears more than once (with exactly the same case), only one entry is required in the output.
inputFormat
The input is provided as a single line from standard input (stdin
). This line is a string which may contain letters, spaces, and punctuation.
outputFormat
The output should be a JSON formatted dictionary printed to standard output (stdout
). Each key is a word (with punctuation removed) and each value is the integer representing that word's length. If no valid word exists, output an empty dictionary: {}.
Hello
{"Hello": 5}