Question: I have a database "records" within it documents of the type:

```
{ ..., ..., "grades" : {"good": "40.0", "bad":"22.0"}}

```

1. I need to get into the document and define a variable as the sum of the "good" and "bad" grades.
2. I don't know how to get inside the imbedded doc,

I tried : 

```
for i in records:
    variable = i['grade.good']

```

But that doesn't seem to work.

Secondly, the grades are strings, and I need to convert them to integers/ 
Again, tried

```
total = int(i['grade.good']) + int(i['grade.bad'])

```

But that it also wrong. 
note that my strings are floating points
Help much appreciated!!

Answer: 
instead of `i['grade.good']` try `i['grade']['good']`

retrieve data from dictionary properly

```
In [11]: d = {"grades" : {"good": "40", "bad":"22"}}

In [12]: d['grades']['good']
Out[12]: '40'

In [13]: total= int(d['grades']['good']) + int(d['grades']['bad'])

In [14]: total
Out[14]: 62

```

for float number 

```
In [21]: d = {"grades" : {"good": "40.0", "bad":"22.0"}}

In [22]: print float(d['grades']['good']) + float(d['grades']['bad'])
62.0

```
The most elegant solution would be:

```
good_grades=[grades['good'] for grades in records] 

```

That will return an array with all of your good grades, do the same thing for bad.

Alternatively, you could simply change this line:

```
variable = i['grade']['good']

```