Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you check if list is blank? [duplicate]

Tags:

Possible Duplicate:
Python: What is the best way to check if a list is empty?

def CleanWhiteSpace(theDict):     stuff=[]      for key,value in theDict.items():         for d in value:             if value != " ":                 stuff.append(d)                     print d                 theDict[key]=stuff             if not value[d]:                 print value         stuff=[]     return theDict     print CleanWhiteSpace({'a':['1','2'],'b':['3',' '],'c':[]}) 

I edited this because I need more help. How do you check if c is blank? Is c is simply equal to []?

I've tried ==[] and "[]" and getting the length and == "", but nothing seems to work.

like image 869
Web Master Avatar asked Jun 13 '12 23:06

Web Master


People also ask

How do you check if a list has no duplicates?

Compare the size of set and list. If size of list & set is equal then it means no duplicates in list. If size of list & set are different then it means yes, there are duplicates in list.

How do you check if a list of lists is empty?

An empty list is denoted using the [] . When a list object is compared with [] using == operator, then it returns True if the list object is empty. Else it returns False . Use the below snippet to check if the list is empty by comparing it with the empty list.

Does empty list evaluate to false?

It evaluates to False if the variable doesn't exist or in the case of a list, when it is empty.

Does an empty list return None?

The empty list, [] , is not equal to None . However, it can evaluate to False --that is to say, its "truthiness" value is False .


1 Answers

In python, an empty list evaluates to False.

if not c:    print "The list is empty" else:    print "The list is not empty" 
like image 56
jordanm Avatar answered Sep 22 '22 15:09

jordanm