Reputation: 87
An API I'm using outputs the coordinates of a face from a picture as follows:
[{'faceId': '59b5b8ad-ea77-455b-bdef-6044883bab6a',
'faceRectangle': {'left': 96, 'top': 51, 'width': 334, 'height': 334}}]
How can I extract the values from just the 'top' and 'left' keys (in this order)? I am looking for a simple output like this:
51
96
Upvotes: 1
Views: 872
Reputation: 53734
Let us assume that your list is named mydict
mydict = [{'faceId': '59b5b8ad-ea77-455b-bdef-6044883bab6a',
'faceRectangle': {'left': 96, 'top': 51, 'width': 334, 'height': 334}}]
now mydict[0]['faceRectangle']
will return:
{'left': 96, 'top': 51, 'width': 334, 'height': 334}
So what you need is
mydict[0]['faceRectangle']['left']
mydict[0]['faceRectangle']['top']
Upvotes: 1