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.

Community
  • 1
  • 1
Web Master
  • 4,240
  • 6
  • 20
  • 28
  • 2
    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
  • 1
    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](http://stackoverflow.com/faq). – Sven Marnach Jun 14 '12 at 00:08

1 Answers1

12

In python, an empty list evaluates to False.

if not c:
   print "The list is empty"
else:
   print "The list is not empty"
jordanm
  • 33,009
  • 7
  • 61
  • 76