Getting math scores (Dictionary inside dictionary)

Steven D'Aprano steve at pearwood.info
Tue Nov 24 06:28:20 EST 2015


On Tue, 24 Nov 2015 10:04 pm, Cai Gengyang wrote:

> results = {
>   "gengyang": { "maths": 10, "english": 15},
>   "ensheng": {"maths": 12, "english": 10},
>   "jordan": {"maths": 9, "english": 13}
>   }
> 
> How do you get gengyang's maths scores ?

Break the problem into two steps:

- get Gengyang's scores;

- then get the maths score:

scores = results['gengyang']
maths_score = scores['maths']


Now you can simplify the process:

maths_score = results['gengyang']['maths']



-- 
Steven




More information about the Python-list mailing list