Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8879007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:51:04+00:00 2026-06-14T19:51:04+00:00

I have a database records within it documents of the type: { …, …,

  • 0

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!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:51:06+00:00Added an answer on June 14, 2026 at 7:51 pm

    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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table within my database that has many records, some records share
I have a database with >100K records and I want to get the results
I have a database containing records collected every 0.1 seconds, and I need to
I need to process XML documents of varying formats into records in a MySQL
I currently have a problem attepting to update a record within my database. I
I'm pretty new to SQL. I have a database with records based on road/milepoints.
I have a function which calculates distance from database records. This function is called
I have an app which will generate 5 - 10 new database records in
I have a database that has around 10k records and some of them contain
I have a database table A which stores records, A has a primary key

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.