I would like to parse an HDF file that has the following format
HDFFile/
Group1/Subgroup1/DataNDArray
...
/SubgroupN/DataNDArray
...
GroupM/Subgroup1/DataNDArray
...
/SubgroupN/DataNDArray
I am trying to use itertools.product but I get stuck on what to use for the second iterator MWE:
from itertools import *
import h5py
hfilename = 'data.hdf'
with h5py.File(hfilename, 'r') as hfile:
for group, subgroup, dim in product(hfile.itervalues(), ????, range(10));
parse(group, subgroup, dim)
Obviously my problem is that the second iterator would depend on the extracted value of the first iterator, which can't be available in the same one liner.
I know that I can do it with for loops or with the following example:
with h5py.File(hfilename, 'r') as hfile:
for group in hfile.itervalues():
for subgroup, dim in product(group.itervalues(), range(10)):
parse(group, subgroup, dim)
but I was wondering if there is a way to do it in one itertools run.