I have a dictionary which holds multiple entries.
e.g. I have response[0]['values']['id']
and response[2]['values']['id']
.
response[0]
has no key 'id'
whereas response[2]
does.
I'm looping through the responses but everytime I try and evaluate
response[0]['values']['id']
it just prints 'id'
. Even if I try if (response[0]['values']['id'])
or type(response[0]['values']['id'])
, it does not evaluate the statement but just prints 'id'
.
response = requests.get (......get command)
test = type((response[0]['value']['id']))
print(test) # 'id'
The statement is not being evaluated and it don't give me the value.
Anyone know why?
Thanks!
CodePudding user response:
maybe a different conditional statement like searching through the dict keys will work
if ('id' in response[0]['values'].keys()): print(response[0]['values']['id'])
CodePudding user response:
Fixed it by adding except Keyerror!