I am trying to generate a list using list comprehension and I want to do an operation on each generated entity. Something like:
a=['1','2','3']
b=['a','b','c']
temp = [[x,y] for x in a for y in b]
c=[]
for t in temp:
c.append("".join(t))
I tried something like:
a=['1','2','3']
b=['a','b','c']
c = ",".join([x,y] for x in a for y in b)
I know this won’t work because the split function has been given a list of lists instead of list of strings. Is there any better way to do this in one go?
The output I am trying to get is ['1a','1b','1c','2a','2b','2c','3a','3b','3c']
1 Answer