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 4096138
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:00:22+00:00 2026-05-20T20:00:22+00:00

Not sure if people refer to slightly older questions but Accessing elements of python

  • 0

Not sure if people refer to slightly older questions but
Accessing elements of python dictionary

Consider a dict like

dict = {
        'Apple': {'American':'16', 'Mexican':10, 'Chinese':5},
        'Grapes':{'Arabian':'25','Indian':'20'} 
       }

How do I access for instance a particular element of this dictionary ? for instance I would like to print first element after some formatting the first element of Apple which in our case is 'American' only ?

Additional information The above data structure was created by parsing an input file in a python function. Once created however it remains the same for that run.

I am using this data structure in my function.

So if the file changes, the next time this application is run the contents of file are different and hence the contents of this data structure will be different but the format would be same. So you see I in my function I don’t know that the first element in Apple is 'American' or anything else so I can’t directly use 'American' as a key.

In short as an input I have a variable v which may have value 'apple' , 'grape' or any other and the above created data structure as an input to my function.

If variable is present in above Data Structure Dict,

Thus if variable==apple or grapes then :
then I need to get it’s corresponding associated elements and print them in a specific format like this ;

Group Apple
   Item "American" Value 16
   Item "Mexican" Value 10

Group Grapes
   Item "Arabian" Value 25
   Item "Indian" Value 20

Group value3 .. 
   and so on

If variable == 'pumpkin' we search for it in the above Dict data structure and since it pumpkin is not present , we dont print anything

etc..

I hope I am able to explain what my want.
Note: It is better that this be merged with above question and so I can accept answers too

  • 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-05-20T20:00:23+00:00Added an answer on May 20, 2026 at 8:00 pm
    for i in dict.keys():
        print "Group", i
        for j in dict[i].keys():
            print "Item", j, "Value", dict[i][j]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not sure if people find this obvious but I have two questions:
I'm not sure if Jeff coined it but it's the joke/saying that people who
Not sure what exactly is going on here, but seems like in .NET 1.1
I'm not sure what people usually mean by lock a file, but what I
I'm not sure if many people know about this text-editor? jEdit was kinda big
I'm not sure how familiar people are with the hobbit monitoring system - http://hobbitmon.sourceforge.net/
I've heard people referring to this table and was not sure what it was
Not sure how to ask a followup on SO, but this is in reference
Not sure if the title is quite right for the question but I can't
Not sure if anyone listened to Hanselminutes episodes 134 and 135, but at the

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.