I have a list of arguments I would like to apply to a list of template format strings. My issue is that each template string can take a variable number of arguments. I want to avoid having a hardcoded list of how many arguments each string takes
counts = [1, 0, 2, 3, 1] # How to get rid of this counts list?
arguments = ["a", "b", "c", "d", "e", "f", "g"]
templates = [
"{} one",
"none",
"{} two {}",
"{} {} three {}",
"one2 {}",
]
start = 0
for i, template in enumerate(templates):
count = counts[i] # a programmatic way to get the count for current template?
print(template.format(*arguments[start : start + count]))
start += count
Output:
a one
none
b two c
d e three f
one2 g
How can I apply a list of strings to a list of format templates without knowing how many variables each format requires?