I want to turn a take two lists and create one long string by looping over each string in each list and concatenating the two separating them by a space:
listA = ["a","b"]
listb = ["1","2","3"]
new_string = "a1 a2 a3 b1 b2 b3"
It is really simple
print( ' '.join([ str(i)+str(j) for i in listA for j in listB]))
' '.join([str(i)+str(j)+' ' for i in listA for j in listB]))Here is a pretty simple solution to the problem, it is usually taught in the beginning of learning for loops (at least it was for me):
listA = ["a","b"]
listb = ["1","2","3"]
new_string = ""
for i in listA:
for j in listb:
#adding a space at the end of the concatenation
new_string = new_string+i+j+" "
print(new_string)
Coded in python 3.
' '.join(map(''.join, itertools.product(listA, listb)))