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.
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.
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.
It evaluates to False if the variable doesn't exist or in the case of a list, when it is empty.
The empty list, [] , is not equal to None . However, it can evaluate to False --that is to say, its "truthiness" value is False .
In python, an empty list evaluates to False.
if not c: print "The list is empty" else: print "The list is not empty"
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