Representation of a relational database: a list of dictionaries or a dictionary with list values?

A relational database has a schema and recordset

I have two ways to represent a relational database in Python:

  • create a list of dictionaries with the same set of keys, where the keys are the names of the schema attributes, and each dictionary represents an entry.

  • create a dictionary where its keys are the names of the attributes of the schema, and the value for each key is a list of the values ​​of the corresponding attribute in the records.

I wonder which way could be easier to operate or have more accessible features? Which method can work more with a relational database?

Does Python have any other (better) data structures / types to represent the same thing?

eg.

a relational database is a table:

name age Joe 10 Mary 6 Tim 8 

The first method gives

 [{name:Joe,age:10}, {name:Mary,age:6}, {name:Tim,age:8}] 

The second method gives

 {name:[Joe,Mary,Tim],age:[10,6,8]} 

Thanks.

0
python dictionary database
source share

No one has answered this question yet.

See similar questions:

2
Apply functions to dictionary values

or similar:

4268
How to combine two dictionaries in one expression?
3474
How to list all the catalog files?
3428
How to sort a dictionary by value?
2683
Check if the given key exists in the dictionary
2679
Iterate over dictionaries using 'for' loops
2391
What is the best way to iterate over a dictionary?
2369
Add new keys to the dictionary?
1687
How to sort a list of dictionaries by dictionary value?
1256
What are the options for storing hierarchical data in a relational database?
994
How to return multiple values ​​from a function?

All Articles