For the following Python dictionary:
dict = {
    'stackoverflow': True,
    'superuser': False,
    'serverfault': False,
    'meta': True,
}
开发者_运维技巧I want to aggregate the boolean values above into the following boolean expression:
dict['stackoverflow'] and dict['superuser'] and dict['serverfault'] and dict['meta']
The above should return me False.  I'm using keys with known names above but I want it to work so that there can be a large number of unknown key names.
in python 2.5+:
all(dict.itervalues())
in python 3+
all(dict.values())
dict is a bad variable name, though, because it is the name of a builtin type
Edit: add syntax for python 3 version. values() constructs a view in python 3, unlike 2.x where it builds the list in memory.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论