#C13886. Nested Key Finder
Nested Key Finder
Nested Key Finder
You are given a JSON string representing a nested dictionary and a target key. Your task is to search for the given key in the nested dictionary recursively. If the key exists, print its corresponding value. If the key is not present anywhere in the nested dictionary, print Key not found
.
The nested dictionary may contain other dictionaries as values. You only need to search within these dictionaries (lists or other types should be ignored).
Note: The input is provided via standard input (stdin) and the output must be printed to standard output (stdout).
Examples:
Input: {"name": "Alice", "details": {"age": 25, "address": {"city": "Wonderland", "postcode": "12345"}}, "hobbies": ["reading", "gardening"]} city Output: Wonderland Input: {"outer": {"middle": {"inner": {"key": "found"}}}} key Output: found
inputFormat
The input consists of two lines read from stdin
:
- A JSON string that represents a nested dictionary.
- A string representing the key to search.
outputFormat
Print the value corresponding to the key if it is found by recursively searching the nested dictionary. Otherwise, print Key not found
.
{"name": "Alice", "details": {"age": 25, "address": {"city": "Wonderland", "postcode": "12345"}}, "hobbies": ["reading", "gardening"]}
city
Wonderland