originData = { 'a': None, 'b': None, 'c': 5, list: [{ 'a': 1, 'b': None}], dict: { 'a': 1, 'b':None}}
def remove_none(data):
if type(data) == dict:
for k in list(data.keys()):
if type(data[k]) == dict or type(data[k]) == list:
remove_none(data[k])
elif data[k] == None:
del data[k]
elif type(data) == list:
for v in data:
if type(v) == dict or type(v) == list:
remove_none(v)
elif v == None:
data.remove(v)
IDE报复杂度过高,请问要如何优化呢?
函数的目的是去除字典originData
中的None值,Python版本是3.6