What's the best way to aggregate the boolean values of a Python dictionary?

Posted by Thierry Lam on Stack Overflow See other posts from Stack Overflow or by Thierry Lam
Published on 2010-05-10T21:34:39Z Indexed on 2010/05/10 21:44 UTC
Read the original article Hit count: 193

Filed under:

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 an infinite number of unknown key names.

© Stack Overflow or respective owner

Related posts about python