I have two lists of dictionaries and would like to loop through the cartesian product as one. How do I do this.
sample data:
environments: [
{title: outdoors, climate: variable},
{title: indoors, climate: steady}
],
colorscheme: [
{top: blue, bottom: red},
{top: pink, bottom: green}
]
desired result:
item: [
{title: outdoors, climate: variable, top: blue, bottom: red},
{title: indoors, climate: steady, top: blue, bottom: red},
{title: outdoors, climate: variable, top: pink, bottom: green},
{title: indoors, climate: steady, top: pink, bottom: green}
]
I have tried the expression "{{ environments|product(colorscheme)|list }}"
which gets me close but not quite what I want.
Results of expression:
item: [
[
{title: outdoors, climate: variable},
{top: blue, bottom: red}
],
[
{title: indoors, climate: steady},
{top: blue, bottom: red}
],
[
{title: outdoors, climate: variable},
{top: pink, bottom: green}
],
[
{title: indoors, climate: steady},
{top: pink, bottom: green}
]
]
Best Answer
Here is one way you could do it. Not sure it is the best eway.