#C12950. Word Lengths Extraction
Word Lengths Extraction
Word Lengths Extraction
Given a sentence as input, your task is to extract all the words and compute their corresponding lengths. A word is defined as a consecutive sequence of alphanumeric characters and underscores (i.e., matching the regular expression \(\texttt{\textbackslash b\textbackslash w+\textbackslash b}\)). The punctuation in the sentence should be ignored.
For example, if the input is Hello world! This is a test.
, the correct output is [('Hello', 5), ('world', 5), ('This', 4), ('is', 2), ('a', 1), ('test', 4)]
.
Your solution should read input from standard input (stdin) and output the result to standard output (stdout) in exactly the shown format.
inputFormat
A single line representing the sentence. The sentence may contain punctuation and numbers.
outputFormat
Print the list of tuples in Python-style representation where each tuple consists of a word and its length.## sample
Hello world! This is a test.
[('Hello', 5), ('world', 5), ('This', 4), ('is', 2), ('a', 1), ('test', 4)]