def clean_dict(d):
if not isinstance(d, (dict, list)):<EOL><INDENT>return d<EOL><DEDENT>if isinstance(d, list):<EOL><INDENT>return [v for v in (clean_dict(v) for v in d) if v]<EOL><DEDENT>return OrderedDict(<EOL>[(k, v) for k, v in ((k, clean_dict(v)) for k, v in list(d.items())) if v]<EOL>)<EOL>
Remove all empty fields in a nested dict