python - One liner conditional, multiple variables and check that all of them are not false? -


how can make conditional in python checks 3 keywords defined in dictionary , not false ?

settings = {     'proxy_host': '127.0.0.1',     'proxy_port': 8080,     'proxy_protocol': 'socks', } 

i have tried sentence can see below. checking these keywords exists in dictionary settings without bothering type of value has.

if 'proxy_host' , 'proxy_port' , 'proxy_protocol' in settings: 

i want if true if none of keywords falsely , exist keys.

use simple generator expression , all():

if all(d.get(k) k in keys): 

example:

keys = ['proxy_host', 'proxy_port', 'proxy_protocol'] if all(settings.get(k) k in keys):     print("settings good!") else:     print("missing setting!") 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -