I have two lists, and want to combine them into one, by each element:
List1 = ['s', 'd', 'c']
List2 = ['a', 'b', 'h']
What I would like:
List = ['sa', 'db', 'ch']
I have two lists, and want to combine them into one, by each element:
List1 = ['s', 'd', 'c']
List2 = ['a', 'b', 'h']
What I would like:
List = ['sa', 'db', 'ch']
List comprehension and zip are the savior for you. Try:
[''.join(i) for i in zip(List1, List2)]
OR you can do:
[i + j for i, j in zip(List1, List2)]
List1 = ['s', 'd', 'c']
List2 = ['a', 'b', 'h']
ls =[]
for i in range(len(List1)):
ls.append(List1[i]+List2[i])
print(ls)