Created
November 6, 2023 06:47
-
-
Save mahmoud/9a1f25b563e9e95f58241e74f864e65c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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