I want to quickly check if one of the attributes (or nested attributes) in a dictionary is equal to "cat".
The dictionary could look like this:
my_dict = {
'dog': 'woof',
'child':{
'duck': 'quack'.
'grandchild': {
'best': 'cat'
}
}
}
Is there a quick way to check if 'cat" is on of the attribute values. I could do something like:
if 'cat' in json.dumps(my_dict):
But that doesn't solve this edge case:
{
'dog': 'woof',
'child':{
'duck': 'quack'.
'grandchild': {
'best', 'This is a cat in a sentence, should be found!'
}
}
}
Any good way to handle this? For this, the dictionaries could be quite large, so looping into each and checking is very computationally expensive.