python 字典列表嵌套

怎样得到annotations中box的后两个元素


{
    "images": [
        {
            "file_name": "6642.jpg",
            "width": 1,
            "height": 1,
            "id": "6642"
        },
        {
            "file_name": "6643.jpg",
            "width": 1,
            "height": 1,
            "id": "6643"
        }
    ],
    "categories": [
        {
            "supercategory": "CYST",
            "name": "CYST",
            "id": 1
        },
        {
            "supercategory": "Effusion",
            "name": "Effusion",
            "id": 2
        }
    ],
    "annotations": [
        {
            "area": 557.0,
            "category_id": 1,
            "image_id": "6642",
            "iscrowd": 0,
            "bbox": [
                303.0,
                317.0,
                27.0,
                21.0
            ],
            "id": 0
        },
        {
            "area": 1420.0,
            "category_id": 2,
            "image_id": "6643",
            "iscrowd": 0,
            "bbox": [
                115.0,
                130.0,
                26.0,
                55.0
            ],
            "id": 1
        }
        ]
}

怎样得到annotations中box的后两个元素

这个简单,一层一层取就行了

dict1 = {
    "images": [
        {
            "file_name": "6642.jpg",
            "width": 1,
            "height": 1,
            "id": "6642"
        },
        {
            "file_name": "6643.jpg",
            "width": 1,
            "height": 1,
            "id": "6643"
        }
    ],
    "categories": [
        {
            "supercategory": "CYST",
            "name": "CYST",
            "id": 1
        },
        {
            "supercategory": "Effusion",
            "name": "Effusion",
            "id": 2
        }
    ],
    "annotations": [
        {
            "area": 557.0,
            "category_id": 1,
            "image_id": "6642",
            "iscrowd": 0,
            "bbox": [
                303.0,
                317.0,
                27.0,
                21.0
            ],
            "id": 0
        },
        {
            "area": 1420.0,
            "category_id": 2,
            "image_id": "6643",
            "iscrowd": 0,
            "bbox": [
                115.0,
                130.0,
                26.0,
                55.0
            ],
            "id": 1
        }
        ]
}
bbox1 = dict1['annotations'][0]['bbox']
bbox2 = dict1['annotations'][1]['bbox']
print(bbox1[2],bbox1[3])
print(bbox2[2],bbox2[3])