In python 2.7 I've got a dictionary of dictionaries, and I'm trying to get values from this in a speedy way. However, sometimes one of the keys (could be either one) doesn't exist in my dictionary, in that case I would like to get a default value.
My dictionary looks like this:
values = { '1A' : { '2A' : 'valAA', '2B' : 'valAB'},
'1B' : { '2A' : 'valBA', '2B' : 'valBB'} }
which works great when I query it with existing keys:
>>> values['1A']['2A']
'valAA'
>>> values.get('1B').get('2B')
'valBB'
How do I get it to do this:
>>> values.get('not a key').get('not a key')
'not present'