我正在尝试搜索嵌套列表中的值,例如name = baby,如果找到匹配项,则打印出列表部分,然后继续搜索其他剩余的嵌套列表。但是无法实现。
CharacterList
字典:
search = 'baby'
for item in results.items():
if search in item:
print ("Found it: ", item)
continue
else:
print("not found")
continue
我正在尝试搜索“值示例”,名称= baby,如果找到匹配项,则打印出“列表部分”,然后继续在其他剩余的嵌套列表中搜索。在我的情况下,如果婴儿是下面的火柴,
results = {
"type": 'information,
"why" : 'needed',
"source": [{
"name": "John",
"age": "20",
"home": "new York"
},{
"name": "Amy",
"age": "21",
"home": "london"
}],
"destinations": [{
"name": "baby",
"age": "40",
"home": "Ohio"
}],
"type": 'information,
"why" : 'needed',
"source": [{
"name": "Dany",
"age": "26",
"home": "Japan"
},{
"name": "Bob",
"age": "21",
"home": "US"
}],
"destinations": [{
"name": "jeny",
"age": "40",
"home": "Dubai"
}]
}