#C13350. Dictionary List Lengths
Dictionary List Lengths
Dictionary List Lengths
Given a dictionary in JSON format where each key is a string and each value may either be a list or another type, your task is to output a new JSON dictionary containing only those keys whose values are lists. For each such key, its corresponding value in the output should be the length of the list from the input.
Formally, let the input dictionary be $$ \{ key: value, \dots \}, $$ then the expected output is $$ \{ key: \ell(value) \}\text{, where }\ell(value)=\text{length of the list}\text{ if }value\text{ is a list, and the pair is omitted otherwise.} $$
The input is provided as a JSON string via standard input and the output should be printed to standard output.
inputFormat
The input consists of a single line containing a valid JSON dictionary. Each key is a string and each value can either be an array (list) or another data type. For example:
{"a": [1, 2, 3], "b": "not a list", "c": [4, 5]}
outputFormat
The output should be a JSON dictionary containing only those key-value pairs from the input where the value is a list. The value for each key in the output is the length of that list. For example, the output corresponding to the above input would be:
{"a": 3, "c": 2}## sample
{"a": [1, 2, 3], "b": "not a list", "c": [4, 5]}
{"a":3,"c":2}