Created
January 25, 2016 15:47
-
-
Save Sukonnik-Illia/7c375d97fd888ae7905b to your computer and use it in GitHub Desktop.
Python ictionary without empty fields
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
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