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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:20:41+00:00 2026-05-20T09:20:41+00:00

I have the following situation in python: I am parsing an ontology and i

  • 0

I have the following situation in python:
I am parsing an ontology and i want to keep track of some properties of the ontology and build a data structure with the below characteristics:

-there will be a single key to access each value

-the value would be another key-value data structure with the following 3 enties:

‘x’:[] a simple list

‘y’:[{‘name’:value,’type’:value}] a list containing specific dictioanry key-values

‘z’:[{‘name’:value,’type’:value}] a list containing specific dictionary key-values

According with the above the final data structure that i though was:

ontology={'': [{'y': {'type': '','name':''}}],'x':[],'z':[ {'type': '', 'name': ''}]}

And finally i want multiple entries of this dinctionary.I do not want to use a list because the index will be an integer and i’d like to index my data through a key.

I will fill this data structure inside 3 different for loops.

At the first loop i will fill in the ontology dictionary with only the key names..I thought something like :

    ontology['a']={'a': [{'y': {'type': '','name':''}}],'x':[],'z':[ {'type': '', 'name': ''}]}

But is this something been doing in the ‘python’ standard way.Is there any other more convinient way of doing this because it seems to me somehow weird.

In the end i’ll have something like this:

ontology['a']={'a':[{'y': {'type': '','name':''}}],'x':[],'z':[ {'type': '', 'name': ''}]}
ontology['b']={'b':[{'y': {'type': '','name':''}}],'x':[],'z':[ {'type': '', 'name': ''}]}
ontology['c']={'c':[{'y': {'type': '','name':''}}],'x':[],'z':[ {'type': '', 'name': ''}]}
ontology['d']={'d':[{'y': {'type': '','name':''}}],'x':[],'z':[ {'type': '', 'name': ''}]}

At the second loop based on the keys i will fill the x :[] value,which is by itself another dictionary

And at the third for loop i will fill the y and z keys.

Is this a good approach for this data structure?I also thought of using Classes in order of my code to be more “structured” but i think i would use much more lines of code

  • 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-20T09:20:42+00:00Added an answer on May 20, 2026 at 9:20 am

    “Lines of code” is probably not the best metric to optimize. This looks like a classic example of outgrowing a “dictionaries and lists” solution. I’ve been there many times. Use a class, it will let you write understandable maintainable code, with named methods for manipulating your data structure.

    This will give you flexibility to hide and change the underlying storage without changing the semantics, or the caller’s view of the data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following Situation, Server A sends some data (HTML form) to server B,
I have the following situation. We want an reputation table to evaluate Users And
I have been learning Python by following some pygame tutorials . Therein I found
I have the following situation in my python code: class Parent(object): def run(self): print
Using Python 2.7 Situation: I have some piece of Python code (that the user
I have following situation - Have a MongoService class, which reads host, port, database
I have following situation. In a constructor of a pseudo class I attach a
I have following situation (simplified, of course): MyDomain.groovy: class MyDomain { MyAnotherDomain anotherDomain //
I have following situation, String a=<em>crawler</em> <em> Yeahhhhh </em></a></h3><table; System.out.println(a.indexOf(</em>)); It returns the 11
I have following situation: String a = A Web crawler is a computer program

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.