如何检查列表是否为空?

Web*_*ter 16 python arrays

可能重复:
Python:检查列表是否为空的最佳方法是什么?

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':[]})
Run Code Online (Sandbox Code Playgroud)

我编辑了这个因为我需要更多帮助.你怎么检查是否c空白?是c简单地等于[]

我已经尝试了==[]"[]"获得了长度== "",但似乎没有任何效果.

jor*_*anm 8

在python中,一个空列表的值为False。

if not c:
   print "The list is empty"
else:
   print "The list is not empty"
Run Code Online (Sandbox Code Playgroud)