Skip to content

Instantly share code, notes, and snippets.

@mahmoud
Created November 6, 2023 06:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mahmoud/9a1f25b563e9e95f58241e74f864e65c to your computer and use it in GitHub Desktop.
Save mahmoud/9a1f25b563e9e95f58241e74f864e65c to your computer and use it in GitHub Desktop.
from boltons.iterutils import is_scalar, remap
garbagey = {'attributes':
{'vars':
{'network':
{'addresses': []}},
'characteristics':
{'chars': 'abc',
'misc_obj': {},
'others': [1, 2]}
}
}
def drop_empty(p, k, v):
return is_scalar(v) or bool(v)
remap(garbagey, visit=drop_empty)
# {'attributes': {'characteristics': {'chars': 'abc', 'others': [1, 2]}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment