检查包含函数返回的多个词典的元组中的任何词典中是否存在键

时间:2016-03-20 17:47:13

标签: python dictionary

是否有可能让一个函数在元组中返回两个字典并检查字典中的值是否在返回两个字典的函数内?前 -

def fooBar():
    a = {"foo": "bar"}
    b = {"bar": "foo"}
    return (a,b)


c = {"foo":"bar"}
for key, value in c.items():
    print(key in fooBar())

我想检查key中的c是否在我的函数fooBar()中的某个位置找到.. key中的c应该{ {1}},"foo"中的一个键是fooBar()

1 个答案:

答案 0 :(得分:3)

如果你想检查一个字典中的键是否在函数返回的字典值中,你可以这样做:

for key in c.keys():
    for dictionary in foobar():
        if key in dictionary.values():
            print("Found: ", key)