Reputation: 413
I have the below nested dictionary:
config = {'trainsets': {'datasets':
{'coco': {'root': 'path1', 'anno': 'anno1', 'num_use': 1, 'frame_range': 2},
'ytb': {'root': 'path2', 'anno': 'anno2', 'num_use': 1, 'frame_range': 3},
'abc': {'root': 'path3', 'anno': 'anno3', 'num_use': 1, 'frame_range': 4}}}}
I need to delete the element 'num_use' for ONLY 'coco'
config = {'trainsets': {'datasets':
{'coco': {'root': 'path1', 'anno': 'anno1', 'frame_range': 2},
'ytb': {'root': 'path2', 'anno': 'anno2', 'num_use': 1, 'frame_range': 3},
'abc': {'root': 'path3', 'anno': 'anno3', 'num_use': 1, 'frame_range': 4}}}}
I tried the below but its not working:
del config['trainsets']['datasets']["coco"]["num_use"]
Upvotes: 0
Views: 57
Reputation: 74
config['trainsets']['datasets']["coco"].pop("num_use")
will surely work
Upvotes: 1