What is the most effective way to check if a list contains only empty values (not if a list is empty, but a list of empty elements)? I am using the famously pythonic implicit booleaness method in a for loop:
def checkEmpty(lst):
    for element in lst:
        if element:
            return False
            break
    else:
        return True
Anything better around?
if not any(lst):
    # ...
Should work.  any() returns True if any element of the iterable it is passed evaluates True.  Equivalent to:
def my_any(iterable):
    for i in iterable:
        if i:
            return True
    return False
                        len([i for i in lst if i]) == 0
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With