arrays - How to read data and create a dictionary of dictionaries in Python? -
arrays - How to read data and create a dictionary of dictionaries in Python? -
i need read huge database hdf5 files , organize in nice way create easy read , use.
i saw post python list variable name , i'm trying create dictionary of dictionaries.
basically have list of info sets , variables need read form hdf5 files. illustration created 2 lists:
dataset = [0,1,2,3] var = ['a','b','c']
now, there legacy "home brewed" read_hdf5(dataset,var) function reads info hdf5 files , returns appropriate array.
i can read specific dataset (say 0) @ time creating dictionary this:
data = {} type in var: data[type] = read_hdf5(0,type)
which gives me nice dictionary if info each variable in dataset 0.
now wan able implement dictionary of dictionaries can able access info this:
data[dataset][var]
that returns array of info given set , variable
i tried next thing loop doing overwriting lastly variable read:
for set in dataset: type in var: data[set] = {'set':set, str(type): read_hdf5(set,type)}
any ideas? give thanks you!!!
you have create new dict each set before iterating on vars:
dataset = [0,1,2,3] var = ['a', 'b', 'c'] info = {} set in datasets: data[set] = {} type in var: data[set][type] = read_hdf5(set, type)
as side note: set
, type
builtin names you'd improve utilize else.
python arrays database database-design dictionary
Comments
Post a Comment