How to check if a value exists in a nested dictionary