framework/geometric_feasibility_predicate/extensions/dict.py

53 lines
1.3 KiB
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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