53 lines
1.3 KiB
Python
53 lines
1.3 KiB
Python
class CoreDict(dict):
|
||
"""
|
||
Class for handling cases related to dictionaries:
|
||
|
||
|
||
Args:
|
||
dict (dict): dictionary to analysis
|
||
"""
|
||
|
||
def isEquivalentByKeys(self, checkDict) -> bool:
|
||
"""
|
||
The function checks whether the values of the keys and the data associated with them match between the processed and the reference dictionary
|
||
|
||
|
||
Args:
|
||
checkDict (dict): reference dictionary
|
||
|
||
Returns:
|
||
bool:
|
||
"""
|
||
|
||
for key in self:
|
||
value = checkDict.get(key)
|
||
if value is None:
|
||
return False
|
||
|
||
return True
|
||
|
||
#
|
||
def isMatchByKeys(self, checkList) -> bool:
|
||
"""
|
||
The function checks whether the key values match the elements of the reference list:
|
||
|
||
Args:
|
||
checkList (list): reference list
|
||
|
||
Returns:
|
||
bool
|
||
"""
|
||
if len(self) != len(checkList):
|
||
return False
|
||
|
||
sorted_dict_keys = sorted(self.keys())
|
||
sorted_list_elements = sorted(checkList)
|
||
|
||
if sorted_dict_keys != sorted_list_elements:
|
||
missing_keys = [
|
||
key for key in sorted_list_elements if key not in sorted_dict_keys
|
||
]
|
||
print(f"Отсутствующие элементы: {missing_keys}")
|
||
return False
|
||
|
||
return True
|