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

Python 检查包含函数返回的多个字典的元组中的任何字典中是否存在键,python,dictionary,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()) 我想检查在我的函数fooBar()中是否找到c中的key。。由于c中的键是“foo”,而fooBar()

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

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


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

我想检查在我的函数
fooBar()
中是否找到
c
中的
key
。。由于
c
中的
键是
“foo”
,而
fooBar()
中的一个键是
“foo”

,如果要检查一个字典中的键是否在函数返回的字典值中,可以执行以下操作:

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

您可能需要将
c.items()
更改为
c.keys()
,以便它实际工作。