PyTown Filesystem

In the world of PyTown, the files in a computer are arranged in a different manner than ours. They are organized in a nested dictionary where keys represent the 'folder names' or 'file names', and the values are either dictionaries representing 'sub-folders' or strings representing 'file extensions'. For instance, a simplified version of the system may look like this:
    'home': {
        'myDocs': {
            'file1': 'txt',
            'file2': 'doc',
            'myPics': {
                'pic1': 'jpg',
                'pic2': 'jpg'
    'etc': {
        'configs': {
            'config1': 'cfg',
            'config2': 'cfg'
Your task is to write a recursive program that can navigate through this nested dictionary and find all files that end with a particular extension.
The first line of the input contains a single string that represents the extension we are searching for. The next line contains the nested dictionary representing the directory structure of PyTown. The dictionary is given as a string, and you need to convert it to a dictionary for further processing (use the json module to. do so).
The program should output a list of all the files that have the given extension. The files should be represented by their complete path separated by a slash (/), similar to UNIX-based file systems. The path should start from the first-level key to the file name, each separated by a /. Print each file on a new line.
cfg { "home": { "myDocs": { "file1": "txt", "file2": "doc", "myPics": { "pic1": "jpg", "pic2": "jpg" } } }, "etc": { "configs": { "config1": "cfg", "config2": "cfg" } } }
etc/configs/config1 etc/configs/config2
Note: The file paths should be in the order of their appearance in the input. The nesting of the dictionaries can be of arbitrary depth.


Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue