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

  • Home
  • SEARCH
  • 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 8205895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:27:04+00:00 2026-06-07T08:27:04+00:00

I have a python dictionary consisting of JSON results. The dictionary contains a nested

  • 0

I have a python dictionary consisting of JSON results. The dictionary contains a nested dictionary, which contains a nested list which contains a nested dictionary. Still with me? Here’s an example:

{'hits':{'results':[{'key1':'value1', 
                    'key2':'value2', 
                    'key3':{'sub_key':'sub_value'}},
                   {'key1':'value3',
                    'key2':'value4',
                    'key3':{'sub_key':'sub_value2'}}
                  ]}}

What I want to get from the dictionary is the sub_vale of each sub_key and store it in a different list. No matter what I try I keep getting errors.

This was my last attempt at it:

inner_list=mydict['hits']['results']#This is the list of the inner_dicts

index = 0
    for x in inner_list:
        new_dict[index] = x[u'sub_key']
        index = index + 1

print new_dict

It printed the first few results then started to return everything in the original dictionary. I can’t get my head around it. If I replace the new_dict[index] line with a print statement it prints to the screen perfectly. Really need some input on this!

for x in inner_list:
    print x[u'sub_key']
  • 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-07T08:27:08+00:00Added an answer on June 7, 2026 at 8:27 am

    After making some assumptions:

    [e['key3']['sub_key'] for e in x['hits']['results']]
    

    To change every instance:

    for e in x['hits']['results']:
     e['key3']['sub_key'] = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a python dictionary of type defaultdict(list) This dictionary is something like this:
I have Python nested list that I'm trying to organize and eventually count number
I have a python dictionary, definition of which does not fit in a single
I have to merge list of python dictionary. For eg: dicts[0] = {'a':1, 'b':2,
I have a python dictionary object that contains a boolean for every key, e.g.:
Let's say I have the following list of python dictionary: dict1 = [{'domain':'Ratios'},{'domain':'Geometry'}] and
I have followed this How do I JSON serialize a Python dictionary? and this
I have a Python list which holds pairs of key/value: l = [[1, 'A'],
While Using Python Dictionary DataStructure (which contains key-value pair) if i want to retrieve
I am parsing JSON requests using the JSON library which parses into python dictionary.

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.