【发布时间】:2022-11-22 19:37:49
【问题描述】:
有两个 dict main 和 input,我想验证“输入”,以便字典和嵌套字典列表中的所有键(如果存在/所有键都是可选的)匹配 main 的键,如果不是错误/不同的键应该作为输出返回
main = "app":[{
"name": str,
"info": [
{
"role": str,
"scope": {"groups": list}
}
]
},{
"name": str,
"info": [
{"role": str}
]
}]
input = "app":[{
'name': 'nms',
'info': [
{
'role': 'user',
'scope': {'groups': ['xyz']
}
}]
},{
'name': 'abc',
'info': [
{'rol': 'user'}
]
}]
当将输入与 main 进行比较时,错误/不同的键应该作为输出给出,在这种情况下
['rol']
【问题讨论】:
标签: python list dictionary recursion comparison