27

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.

4
  • 2
    How do you define "blank"? Simply a list with no elements? Commented Jun 13, 2012 at 23:44
  • I (and others) actually used if c in the answers to your previous question. You might learn something by studying these answers carefully. Commented Jun 13, 2012 at 23:47
  • 1
    Trying to get the length as you say was the right idea, that should have worked. Commented Jun 13, 2012 at 23:47
  • 2
    @WebMaster: If you want an question to be deleted, flag it for moderator attention and provide a good reason why it should be deleted. This question was closed because it's a duplicate. Please take the time to read StackOverflow's FAQ. Commented Jun 14, 2012 at 0:08

1 Answer 1

12

In python, an empty list evaluates to False.

if not c: print "The list is empty" else: print "The list is not empty" 
Sign up to request clarification or add additional context in comments.

1 Comment

doesn't work if not key: del theDict[key] still prints out {'a': ['1', '2'], 'c': [], 'b': ['3', ' ']}

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.