+2 votes
in Programming Languages by (6.7k points)
I have two lists and want to generate a new list that will have elements of two list concatenated.

E.g: Input lists:

aa = ['a','b','c']
bb = ['x','y','z']

Output list: ['ax', 'by', 'cz']

Any quick pythonic way?

1 Answer

0 votes
by (12.7k points)

Here are two simple approaches that you can try to get the desired result:

Approach 1:

aa = ['a','b','c']
bb = ['x','y','z']
def doConcatenate(i,j):
    return i+j
result = map(doConcatenate, aa, bb)
print (result)

Approach 2:

aa = ['a','b','c']
bb = ['x','y','z']
t = []
for i,j in zip(aa,bb):
    t.append(i+j)
print (t)

...