Note that there are some explanatory texts on larger screens.

plurals
  1. POWhich is the best approach of this data structure in python?
    primarykey
    data
    text
    <p>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:</p> <p>-there will be a single key to access each value</p> <p>-the value would be another key-value data structure with the following 3 enties:</p> <p>'x':[] a simple list</p> <p>'y':[{'name':value,'type':value}] a list containing specific dictioanry key-values</p> <p>'z':[{'name':value,'type':value}] a list containing specific dictionary key-values</p> <p>According with the above the final data structure that i though was:</p> <pre><code>ontology={'': [{'y': {'type': '','name':''}}],'x':[],'z':[ {'type': '', 'name': ''}]} </code></pre> <p>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.</p> <p>I will fill this data structure inside 3 different for loops.</p> <p>At the first loop i will fill in the ontology dictionary with only the key names..I thought something like :</p> <pre><code> ontology['a']={'a': [{'y': {'type': '','name':''}}],'x':[],'z':[ {'type': '', 'name': ''}]} </code></pre> <p>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.</p> <p>In the end i'll have something like this:</p> <pre><code>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': ''}]} </code></pre> <p>At the second loop based on the keys i will fill the x :[] value,which is by itself another dictionary </p> <p>And at the third for loop i will fill the y and z keys.</p> <p>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</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload