I am working on a program to delete blank values from lists inside dictionaries, however if the entire value consists of a single array that holds only a single space, I need to delete the element containing the single space.
def CleanWhiteSpace(theDict) :
stuff=[]
for key2 in theDict.keys():
for value2 in theDict.values():
if value2 == [' ']:
print key2
del theDict[key2]
print "hi"
print theDict
for key,value in theDict.iteritems():
for d in value:
print value
if d != ' ':
stuff.append(d)
theDict[key]=stuff
stuff=[]
return theDict
print CleanWhiteSpace({'a':['1','2'],'b':['3',' '],'c':[' ']})
I only want this to delete key c.
For each key, you should only look at a single value, rather than looping over
theDict.values().