alist = []
atuple = ()
aset = set() # Sadly, no literal for sets!
adict = {}
Tag Archives: empty
Python: Checking if nested list is essentially empty
# Also see: http://stackoverflow.com/questions/1593564
# Note: all([]) returns True
def isListEmpty(inList):
if isinstance(inList, list): # Is a list
return all( map(isListEmpty, inList) )
return False # Not a list
Python: Check if list is empty
aList = []
if not aList: # Check if list is empty
print( "Empty" )
else:
print( "Not empty" )
alist.append( 42 )
if alist: # Check if list is not empty
print( "Not empty" )
else:
print( "Empty" )
# Output:
# Empty
# Not empty