#C13813. Strings to Length Dictionary
Strings to Length Dictionary
Strings to Length Dictionary
You are given a list of strings. Your task is to compute the length of each unique string and output a dictionary mapping each string to its length. The keys of the dictionary must be sorted in lexicographical order.
The output should follow the exact Python dictionary format: {"key1": value1, "key2": value2, ...}
. For example, given the list ["apple", "banana", "cherry"], the resulting dictionary is {"apple": 5, "banana": 6, "cherry": 6}
.
Note: Duplicate strings should be processed only once and strings may be empty.
inputFormat
The first line of input contains an integer n, representing the number of strings. The following n lines each contain a single string. A string can be empty.
outputFormat
Output the dictionary mapping each unique string to its length. The dictionary must be formatted as a Python dictionary literal (with keys quoted) and the key-value pairs should be sorted in lexicographical order. If no strings are provided, output {}
.
3
apple
banana
cherry
{"apple": 5, "banana": 6, "cherry": 6}