dkutils.dictionary_comparator module

class dkutils.dictionary_comparator.DictionaryComparator(left, right)[source]

Bases: object

Utility that can be used to perform a shallow comparison on two dictionaries.

Parameters
  • left (dict) – Left dictionary.

  • right (dict) – Right dictionary

__init__(left, right)[source]

Utility that can be used to perform a shallow comparison on two dictionaries.

Parameters
  • left (dict) – Left dictionary.

  • right (dict) – Right dictionary

get_keys_in_both()[source]

Return the set of keys that are present on botch sides

Returns

The keys that are present in both sides

Return type

set

get_keys_only_in_left()[source]

Returns the set of keys that are only present in the left side

Returns

The keys that are only present in the left

Return type

set

get_keys_only_in_right()[source]

Returns the set of keys that are only present in the right side

Returns

The keys that are only present in the right

Return type

set

get_same_keys_different_values()[source]

Get the key and values where the keys were the same for left and right but the values differed

Returns

A dictionary where the key is the keys that occured in both left and right and the value is a tuple made up of the value from the left and the value from the right

Return type

dict

left_equals_right()[source]

Test is the the left dictionary is equal to the right dictionary.

Returns

Returns True if the keys and values in left are equal to those in right

Return type

bool

merge_left()[source]

Merge the dictionaries with preference being given to dictionary on the right if a key exists on both sides. For example given:

left = {'one': 1, 'two': 2, 'three': 3 }
right = {'two': 2, 'three': 'III' }

merge_left will result in the following:

{'one': 1, 'two': 2, 'three': 'III', 'four': 4 }
Returns

A dictionary containing the keys and values from left and right. The value from the dictionary on the right will be returned if a key exists in both dictionaries

Return type

dict

merge_right()[source]

Merge the dictionaries with preference being given to dictionary on the left if a key exists on both sides. For example given:

left = {'one': 1, 'two': 2, 'three': 3 }
right = {'two': 2, 'three': 'III' }

merge_left will result in the following:

{'one': 1, 'two': 2, 'three': '3', 'four': 4 }
Returns

A dictionary containing the keys and values from left and right. The value from the dictionary on the left will be returned if a key exists in both dictionaries

Return type

dict

property left
property right