0

How can I find in a list of dictionaries that it contain at least one value.

I found a couple of answers to this question but in all of them they suppose you know the key name in this case I don't know what's the name of the key.

Example:

 dic_list = [
              {u'12': False, u'3': True, u'6': False, u'9': False},
              {u'12': False, u'3': False, u'6': False, u'9': False}
            ]

How can I return True if there's at least one True as a value in either of these dictionaries without having to do a nested for loop?

Rafael Tamayo
  • 362
  • 2
  • 4
  • 15

1 Answers1

3

With builtin any function:

has_true = any(True in d.values() for d in dic_list)
RomanPerekhrest
  • 88,541
  • 4
  • 65
  • 105