Python 在听写理解中包括bool

Python 在听写理解中包括bool,python,python-3.x,dictionary,compression,Python,Python 3.x,Dictionary,Compression,我有一个返回dict理解的函数。我不知道如何理解返回两个布尔。现在我已经设置好了,如果x发生,字典的值为True,但是如果y发生在一个理解中,我如何合并False呢 def function......: print('Are these the oldest?') return [dict_key: True for dict_key in dict if d[dict_key] ==0] 您可以在理解中使用三元条件: {dict

我有一个返回dict理解的函数。我不知道如何理解返回两个布尔。现在我已经设置好了,如果x发生,字典的值为True,但是如果y发生在一个理解中,我如何合并False呢

    def function......:  
        print('Are these the oldest?')         
        return [dict_key: True for dict_key in dict if d[dict_key] ==0]

您可以在理解中使用三元条件:

{dict_key: True if <condition> else False for dict_key in ...}
{dict_key:True如果在…中dict_key为False,则为True}
或者您可以只使用条件本身的结果:

{dict_key: <condition> for dict_key in ...}
{dict_key:for dict_key in…}

尽管大多数人都能理解你的要求,但你应该包含你的代码,向我们展示你所拥有的,以及你迄今为止理解如何做的,以及你可能做错了什么。你有列表理解,而不是听写理解。