Flatten the list of tuples, and zip it with the repeating sequence of explicit variable names.
from itertools import chain, cycle, product
for var, value in zip(cycle(["A", "B"]),
chain.from_iterable(product(*iterables))):
print(var, value)
chain.from_iterable
turns something like (x, y), (x, y)
into x, y, x, y
. cycle([x,y])
produces x, y, x, y, ...
. The cycle is infinite, but zip
only consumes as much as needed to exhaust the flattened product sequence.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…