I have two lists that I’m trying to combine:
lst1 = [['arg1', 'arg2']] # this can have more lists, but for simplicity, leaving it as this
lst2 = ['arg3', 'arg4']
I want the product of the two lists so that the product is:
[['arg1', 'arg2', 'arg3'], ['arg1', 'arg2', 'arg4']]
I can obviously loop through and do this, but I need to be able to do this as a one-liner (I have reasons).
I’ve been able to do this by doing the following:
list(
map(
lambda l: list(itertools.chain.from_iterable(l)),
list(itertools.product(lst, lst2)),
)
)
…which is okay, but I’m wondering if there’s a bette way to do this. I also feel like there should be a more mathematical way to express what I’m describing? Maybe itertools
isn’t the right library?