#C14561. Word Length Dictionary
Word Length Dictionary
Word Length Dictionary
Given a string consisting of words separated by one or more spaces, your task is to compute a dictionary (associative array) where each key is a distinct word and the corresponding value is the length of that word. Words are not modified (i.e. punctuation remains attached).
For example, if the input is hello world this is a test
, the output should be {'hello': 5, 'world': 5, 'this': 4, 'is': 2, 'a': 1, 'test': 4}
.
Note: There may be multiple spaces between words. If the input string is empty, output an empty dictionary: {}
.
inputFormat
The input consists of a single line containing the string S
. S
may be empty or may contain multiple spaces between words.
outputFormat
Output the dictionary representation (using Python dictionary literal style) of the unique words and their lengths. The keys should appear in the order of their first occurrence in the input string.
## samplehello world this is a test
{'hello': 5, 'world': 5, 'this': 4, 'is': 2, 'a': 1, 'test': 4}