I have two lists of strings:
l1 = ["Col1", "Col2", "Col3"]
l2 = ["_ad1", "_ad2"]
and I want to get the cartesian product / Concatenation of both lists l1
x l2
into a single element, i.e. my desired result is:
["Col1_ad1", "Col1_ad2", "Col2_ad1", "Col2_ad2", "Col3_ad1", "Col1_ad1"]
Of course I could to something like:
result = []
for colname in l1:
for suffix in l2:
result.append(f"{colname}{suffix}")
But I was wondering whether there is a more pythonic way?
EDIT: I am not looking for a more pythonic way to formulate the loop (i.e. list comprehension). Instead I am looking for an inbuilt function, something like
concatenate(l1, l2)
that yields the desired result