Documentation¶
-
class
melddict.
MeldDict
¶ Bases:
dict
A dict subclass which supports adding and subtracting.
-
add
(other)¶ Recursively merge another Mapping into this one, adding to or replacing the existing key / values.
Corresponding values which are both Mappings will be converted to a MeldDict and added (i.e., recursively).
Corresponding values that are both Iterable (but not strings) will be added or replaced according to
meld_iters
.Otherwise, corresponding values will be replaced. Non-corresponding values from the other Mapping will be inserted into this one.
You can also perform addition using the forward, reverse, and in-place operators:
meld_dict = MeldDict({...}) norm_dict = {...} meld_dict + norm_dict norm_dict + meld_dict meld_dict += norm_dict norm_dict += meld_dict
-
meld_iters
= True¶ Whether or not to meld Iterables as well.
When adding, corresponding values which are both Iterable are converted to a list of all the items. When subtracting, corresponding values which are both Iterable are converted to a list with common items removed, while other items are ignored. Corresponding values where the types don’t match are replaced or ignored.
-
remove_emptied
= False¶ Whether or not to remove Mappings or Iterables that are completely empty after subtraction.
-
subtract
(other)¶ Recursively subtract another Mapping from this one, removing corresponding the existing key / values.
Corresponding values which are both Mappings will be converted to a MeldDict and subtracted.
Corresponding values that are both Iterable (but not strings) will be subtracted or not according to
meld_iters
.Otherwise, corresponding keys will be deleted. Non-corresponding keys will be ignored.
You can also perform subtraction using the forward, reverse, and in-place operators:
meld_dict = MeldDict({...}) norm_dict = {...} meld_dict - norm_dict norm_dict - meld_dict meld_dict -= norm_dict norm_dict -= meld_dict
-