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.
python dictionary database
Tim
source share