Hurry! Write an interface to find the number of descendants of a particular element Linux in the dictionary structure?

< H2 > question < / H2 >

write an interface to find the number of descendants of a specific element Linux in the dictionary structure data
[recursion should be used, known result should be 7]

unix_tree = {
            "Unix": {
                "PWB/Unix": {
                    "System III": {
                        "HP-UX": None
                    },
                    "System V": {
                        "UnixWare": None,
                        "Solaris": {
                            "OpenSolaris": None
                        }
                    }
                },
                "BSD": {
                    "Unix 9": None,
                    "FreeBSD": None,
                    "NetBSD": None,
                    "MacOS": None
                },
                "Xenix": {
                    "Sco Unix": {
                        "OpenServer": None
                    },
                    "AIX": None,
                },
            },
            "Linux": {
                "Debian": {
                    "Ubuntu": None,
                    "Linux Mint": None
                },
                "Redhat": {
                    "CentOS": None,
                    "Fedora": None
                },
                "Gentoo": None
            }
        }


def count_of_all_distributions_of_linux(unix_tree):
    pass

topic description

sources of topics and their own ideas

related codes

/ / Please paste the code text below (do not replace the code with pictures)

what result do you expect? What is the error message actually seen?

Apr.03,2021

use the recursive method. It's very short. Look at

.
def get_dictkeys(dic):
    key_sum = 0
    for key in dic.keys():
        key_sum = key_sum+1
        if isinstance(dic[key], dict):
            key_sum = key_sum+get_dictkeys(dic[key])
    return key_sum
print get_dictkeys(unix_tree["Linux"])
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b37fd2-2c0cd.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b37fd2-2c0cd.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?