Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Completely Empty by johan4622
def completely_empty(val):
if val == "":
return True
elif hasattr(val,"__iter__") or hasattr(val, "__getitem__"):
if type(val) is dict:
if len(val) == 1 and "" in val.keys():
return True
else:
return False
else:
if hasattr(val, "__len__") and len(val) == 0:
return True
if not (hasattr(val, "append") or hasattr(val, "__next__") or hasattr(val, "__getitem__")):
return False
results = []
for v in val:
results.append(completely_empty(v))
return True if results.count(False) == 0 else False
else:
return False
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
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')
Dec. 31, 2018