2

I'm trying to loop over a dictionary with nested keys to see if they're identical or not. If they are not (IE, false) I need to trigger separate logic in my program.

I've pasted an example of the dictionary/JSON where I'm looking to check if the nested key_of_interest are all the same. In this case, they are false (abc vs def)

[{'name': 'set-1',
  'name': [{'name': 'rule-1',
    'outer_key': {'key_of_interest': {'secondary_key': [None]}}},
   {'name': 'rule-2',
    'outer_key': {'key_of_interest': [None]}}]}]

I've tried various combinations of if all without success... any guidance would be appreciated.

Thanks! Edit: Reason why 'Elegant way to check if a nested key exists in a python dict' doesn't apply is discussed below

Numpty
  • 1,461
  • 5
  • 19
  • 28
  • Possible duplicate of [Elegant way to check if a nested key exists in a python dict](https://stackoverflow.com/questions/43491287/elegant-way-to-check-if-a-nested-key-exists-in-a-python-dict) – Jtcruthers Oct 18 '19 at 19:52
  • Eh, it's less about searching for a specific key to see if it exists (it could be anything...), it's that they're all equal (or not) to each other. – Numpty Oct 18 '19 at 20:13
  • Are you just worried the keys are the same or the actual values are equal? – Jtcruthers Oct 18 '19 at 20:14
  • 1
    Technically I'm worried if the keys are *not* equal (==). They're strings, not that it should matter. Just need to iterate over all keys (could be 100's) to make sure they're identical. If not, I have to add additional logic – Numpty Oct 18 '19 at 20:22
  • In the example are you trying to check whether the __values__ under all the keys called `key_of_interest` are the same? (Also what does `abc` vs `def` refer to?) – Uri Granta Oct 19 '19 at 14:23

0 Answers0