Let's say I have a Python dict that may contain other dicts nested to an arbitrary level. Also, some of the keys refer to boolean choices while others don't. Something like this:
{'Key1': 'none',
'Key2': {'Key2a': True, 'Key2b': False},
'Key3': {'Key3a': {'Key3a1': 'some', 'Key3a2': 'many'}, 'Key3b': True}}
What I'd like to do is transform it into this:
{'Key1_none': 1,
'Key2_Key2a': 1,
'Key2_Key2b': 0,
'Key3_Key3a_Key3a1_some': 1,
'Key3_Key3a_Key3a2_many': 1,
'Key3b': 1}
Now now only is the dict flattened, all of the keys now have boolean answers. This solution is a great start, but I'm not that familiar with Python. The solution I linked to handles most of the cases, but it doesn't drill-down to the value level in all cases. With the example above, it would leave the first part as:
{'Key1': 'none',
'Key2_Key2a': 1,
'Key2_Key2b': 0,
...}
Obviously replacing the True/False with 1/0 is trivial. My question is more about how to flatten down to the additional level when the value of the key is not True or False.