Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Solution with Generator solution in Clear category for Completely Empty by bsquare
from collections.abc import Iterable
def flatten(collection):
for item in collection:
if isinstance(item, Iterable) and not isinstance(item, str):
yield from flatten(item)
elif isinstance(item, int) or item is None or item:
yield item
def completely_empty(val):
return not list(flatten(val))
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert completely_empty([[], "test"]) == False, "Trick with string"
assert completely_empty([]) == True, "First"
assert completely_empty([1]) == False, "Second"
assert completely_empty([[]]) == True, "Third"
assert completely_empty([[],[]]) == True, "Forth"
assert completely_empty([[[]]]) == True, "Fifth"
assert completely_empty([[],[1]]) == False, "Sixth"
assert completely_empty([0]) == False, "[0]"
assert completely_empty(['']) == True
assert completely_empty([[],[{'':'No WAY'}]]) == True
print('Done')
July 31, 2019