ex1 = {'value': '1, 2, 2, 3, 2, 2, 3, 3, 4, 3, 3, 5, 5, 5, 5, 5, 5, 5', 'number': '1197916152', 'key': '44'}
ex2 = {'number': '1197916152', 'key': '2'}
I've got a dictionaries like above. I need to check if a dict
contains value
key, and if not, return 1
. I tried with the following:
np.where('value' in ex1, ex1['value'], 1)
np.where('value' in ex2, ex2['value'], 1)
And while it works fine with ex1
, it returns an error with ex2
:
KeyError Traceback (most recent call last) ' in () ----> 1 np.where('value' in ex2, ex2['value'], 1)
KeyError: 'value'
It seems ex2['value']
seems to be evaluated even when a condition is not fulfilled. Am I right? And how can I adjust that?