omitempty
is a Python module to remove empty keys in a dictionary. Its name
comes from Go’s json
package which supports an omitempty
tag not to
marshal empty struct fields.
The module exposes only one function that takes a dictionary and remove all keys with falsy values.
[sudo] pip install omitempty
The library works with both Python 2.x and 3.x.
Import the module and use it directly:
import omitempty d = omitempty({"a": a(), "b": b(), "c": c()})