美文网首页
python 字典嵌套校验

python 字典嵌套校验

作者: 高峥 | 来源:发表于2020-04-16 12:32 被阅读0次
d = {"a": {"one": "one", "v": {"c": "e"}}, "b": {"c": "c"}}
c = {"a": {"v": {"c": "c"}, "one": "one"}, "b": {"c": "c"}}

def ver(resp, body):
    for k, v in body.items():
        if k in resp.keys():
            if isinstance(v, dict):
                 if not ver(v, resp[k]):
                     return False
            elif isinstance(v, str):
                if v != resp[k]:
                    return False
    return True


x = ver(d, c)

print x

相关文章

网友评论

      本文标题:python 字典嵌套校验

      本文链接:https://www.haomeiwen.com/subject/aykrvhtx.html