递归遍历嵌套的python字典,并检查给定值是否存在。 (N个字典)

时间:2019-05-24 08:09:19

标签: python python-3.x

我正在尝试查找给定的“ id”(如果它存在于字典中)。问题在于,由于字典的不断增长,我无法预测它的长度。一些雇员可能有空的sub_employee [],但有些雇员将有N个sub_employee。

我的示例词典

datas = {{
    "profileid": {
        "id": 98,
        "first_name": "xxx",
    },
    "sub_employees": [
        {
            "profileid": {
                "id": 101,
                "first_name": "xxx",
            },
            "sub_employees": [
                {
                    "profileid": {
                        "id": 102,
                        "first_name": "xxx",
                    },
                    "sub_employees": []
                },
                {
                    "profileid": {
                        "id": 109,
                        "first_name": "xxx",
                    },
                    "sub_employees": [
                        {
                            "profileid": {
                                "id": 110,
                                "first_name": "xxx",
                            },
                            "sub_employees": [
                                {
                                    "profileid": {
                                        "id": 111,
                                        "first_name": "xxx",
                                    },
                                    "sub_employees": []
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ]
}}

如何查找给定词典中是否存在特定的“ id”

0 个答案:

没有答案