本文介绍了你如何检查,如果列表为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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.
解决方案
In python, an empty list evaluates to False.
if not c:
print "The list is empty"
else:
print "The list is not empty"
这篇关于你如何检查,如果列表为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!