Let's suppose that I have a nested dictionary which looks like that:
parent_dict = { 'parent_key': {'child_key': 'child_value'}
How can I write the following code:
if parent_dict.get('parent_key') is not None and parent_dict['parent_key']['child_key']=='value_1':print('Value detected')
in a more efficient way in terms of readability and amount of code?
Specifically I think that the first if condition could be somehow integrated with the second one in one condition.
So for I would like it to be like that:
if condition_x:print('Value detected')
where condition_x
checks both if the parent dict
is not empty and if not then it returns the value of the child dict
otherwise it returns None
.