Oftentimes, we call functions over a wide range of parameter values, e.g. to generate plots for different scenarios. For multiple parameters, this leads to ugly multi-loops and cumbersome boilerplate. With this snippet it becomes one line.
Let’s say that we have a plotting function plot
and call it for multiple values a
, b
and c
and want to reflect these numbers in the filename of the plot. Then the naive way to do this
is the following:
for a in [1, 2, 3]:
for b in [4, 5, 6]:
for c in [7, 8, 9]:
plot(a=a, b=b, c=c, filename="{a}{b}{c}.pdf")
With the following snippet, we can do the same thing in just one line:
product_call(plot, multi=dict(a=[1, 2, 3], b=[4, 5, 6], c=[7, 8, 9]), static=dict(filename="{a}{b}{c}.pdf")
Here’s the snippet: