I create a default dict in my code something like below:
defaultdict(
<class 'list'>
, {'month': ['JAN', 'FEB'], 'car': ['baleno', 'santro'], 'measure': ['sales', 'expense']})
cube = 'test'
Now I would like to print above dict in the below format by adding variable cube
:
['month', 'JAN', 'car', 'baleno', 'measure', 'sales', 'test']
['month', 'JAN', 'car', 'baleno', 'measure','expense', 'test']
['month', 'JAN', 'car', 'santro', 'measure', 'sales', 'test']
['month', 'JAN', 'car', 'santro', 'measure', 'expense', 'test']
['month', 'FEB', 'car', 'baleno', 'measure','sales', 'test']
['month', 'FEB', 'car', 'baleno', 'measure','expense', 'test']
['month', 'FEB', 'car', 'santro', 'measure','sales', 'test']
['month', 'FEB', 'car', 'santro', 'measure','expense', 'test']
I'm actually using three loops to achieve the above output, but would like to get a neat one.
dim=['month','car','measure']
cube='test'
for b in itertools.product(*(k.values())):
list1 = list()
for (f, c) in zip(b, dim):
list1.append(c)
list1.append(f)
list1.append(cube)
print(list1)
k is the default dict
PS: I'm new to PYTHON. Just using it for the couple of months.