When I want to check if multiple keys and values are in the dictionary type, I thought that any or all could be used, so I will write it as Tips
For example, check if there are 3 required items and the settings are in the config file
settings = {} # <--The settings are loaded here
#For example, REDIS_HOST and REDIS_PORT and REDIS_When you want to check if there is a key called DB
if not settings['REDIS_HOST'] or not settings['REDIS_PORT'] or not settings['REDIS_DB']:
print('error')
Don't do it like
requirements = ['REDIS_HOST', 'REDIS_PORT', 'REDIS_DB']
if not all(x in settings for x in requirements):
print('error')
Can be done like
Recommended Posts