I have the following Python tuple:
my_tuple = ( "key1", ("nested_key1", "nested_key2"), "key3")
I am required to test if a dict contains either "key1"
, all elements in ("nested_key1", "nested_key2")
, or "key3"
. If there is a match for all elements at any of the root tuple's indexs, then the algorithm should only evaluate as True
if there are NO other matches in other indexes. If there are additional keys not specified in the tuple, these can be disregarded for matching purposes.
Meaning that...
These should return True:
matching_dict_root = {"key1": 1}
matching_dict_nested = {"nested_key1": 2, "nested_key2": 3}
unspecified_keys_are_allowed = {"key1": 1, "99problems": 99}
These should be False:
too_many = {"key1": 1, "nested_key1": 1, "nested_key2": 2}
also_wrong = {"key1": 1, "nested_key2": 1}
Can assume (for my current case, but general solutions are most welcome):
- only 1 nested level
- all individual attributes (at all depths) are globally unique
Python-3.6 please, Python-2.7 also helpful, but not required. If possible (I presume it is, and that I'll kick myself), std. lib. only.