Check for existence of False as value in nested dictionary

Is there an easy way to find occurrence of False as value, anywhere in Python nested dictionary. I can of course loop through the keys and values but, maybe there is a better way, especially when we do not know the depth of nested dictionary.

Example below dictionary should return False, as there is one occurrence of False

{'metric1': {'details': {'baseline': {'actual': 1,
                                      'lower_bound': 1,
                                      'result': True,
                                      'upper_bound': 2}},
             'result': True},
 'metric2': {'details': {'baseline': {'actual': 0,
                                      'lower_bound': 1,
                                      'result': False,
                                      'upper_bound': 2}},
             'result': None},
 'metricbool': {'details': None, 'result': True}}

Read more here:

Content Attribution

This content was originally published by Gaurav Pathak at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: