#C12471. Sorted Words Length
Sorted Words Length
Sorted Words Length
Given a sentence as input, process the sentence by removing all punctuation and converting all characters to lower-case. Then, split the sentence into words and generate a list of tuples. Each tuple should contain a word and its length. Finally, sort the list so that words appear in increasing order of length. If two words have the same length, they should be sorted in lexicographical order.
For example, if the input is:
An apple a day keeps the Doctor away!
After processing, the output should be:
[('a', 1), ('an', 2), ('day', 3), ('the', 3), ('away', 4), ('apple', 5), ('keeps', 5), ('doctor', 6)]
Note: Ignore punctuation, consider case insensitivity, and handle any exceptions appropriately.
inputFormat
The input consists of a single line that contains a sentence. The sentence may include punctuation and mixed case letters.
outputFormat
The output is a list of tuples. Each tuple contains a word (in lower-case) and its corresponding length. The list must be sorted first by the length of words (in ascending order) and then lexicographically for words of equal length. The output should be printed as a single line to stdout.
## sampleAn apple a day keeps the Doctor away!
[('a', 1), ('an', 2), ('day', 3), ('the', 3), ('away', 4), ('apple', 5), ('keeps', 5), ('doctor', 6)]