目的:清除json中的空值或垃圾
- type()有可能遇到不是string,此時若沒判斷就會因為用replace()發生exception,當然如果用try statement也是可以的
- test one variable against multiple values可以用in
- 要注意是==str而非==’str’
for i in head.copy(): if(type(head[i])==str): head[i] = head[i].replace(' ', '') # 去除全形空白 if(head[i] in ('', None, '()', {}) or i==''): del head[i];