Python: Check if all dictionaries in list are empty

Posted by Brant on Stack Overflow See other posts from Stack Overflow or by Brant
Published on 2010-03-19T17:54:44Z Indexed on 2010/03/19 18:01 UTC
Read the original article Hit count: 167

Filed under:

I have a list of dictionaries. I need to check if all the dictionaries in that list are empty. I am looking for a simple statement that will do it in one line.

Is there a single line way to do the following (not including the print)?

l = [{},{},{}] # this list is generated elsewhere...
all_empty = True
for i in l:
  if i:
    all_empty = False

print all_empty

Somewhat new to python... I don't know if there is a shorthand built-in way to check this. Thanks in advance.

© Stack Overflow or respective owner

Related posts about python