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

def CleanWhiteSpace(theDict):

    for key,value in theDict.items():
        for d in value:
            if value != " ":
                print d
            if not value[d]:
                print value
    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.

  • How do you define "blank"? Simply a list with no elements? – Andrew Marshall Jun 13 '12 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. – Sven Marnach Jun 13 '12 at 23:47
  • Trying to get the length as you say was the right idea, that should have worked. – Levon Jun 13 '12 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. – Sven Marnach Jun 14 '12 at 0:08

In python, an empty list evaluates to False.

if not c:
   print "The list is empty"
   print "The list is not empty"
  • doesn't work if not key: del theDict[key] still prints out {'a': ['1', '2'], 'c': [], 'b': ['3', ' ']} – Web Master Jun 13 '12 at 23:47
