在字典中查找值表格嵌套列表并打印部分

时间:2019-05-16 11:48:41

标签: python-3.x list api dictionary

我正在尝试搜索嵌套列表中的值,例如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"
        }]

}

0 个答案:

没有答案