python - Splitting nested dictionary -
i have nested dictionary per below. looking remove initial data item. left inner dictionary {0: 'information1', 1: 'information2', 2: 'information3'}.
all information have found far suggests splitting based on value , after value of data not entirely sure how specify split.
initial nested dictionary
{'data': {0: 'information1', 1: 'information2', 2: 'information3'}} expected result dictionary
{0: 'information1', 1: 'information2', 2: 'information3'}
you not trying split, retrieve 1 of values inside dictionary:
d = {'data': {0: 'information1', 1: 'information2', 2: 'information3'}} inner = d['data'] inner contain {0: 'information1', 1: 'information2', 2: 'information3'}
a bit more explanation:
looking @ d, contains 1 key/value pair. key 'data' , value {0: 'information1', 1: 'information2', 2: 'information3'}.
now value d associated key 'data', use syntax [] , use key:
inner = d['data']
this return value , assign inner. can access values within inner in same way. inner[1] information2.
Comments
Post a Comment