Skip to content

Instantly share code, notes, and snippets.

@Sukonnik-Illia
Created January 25, 2016 15: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 Sukonnik-Illia/7c375d97fd888ae7905b to your computer and use it in GitHub Desktop.
Save Sukonnik-Illia/7c375d97fd888ae7905b to your computer and use it in GitHub Desktop.
Python ictionary without empty fields
class DictNoNone(dict):
"""Delete empty fields from dictionary """
def __init__(self, initial_dict={}):
for key in initial_dict:
self.__setitem__(key, initial_dict[key])
def __setitem__(self, key, value):
if key in self or value:
dict.__setitem__(self, key, value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment