user3030473 user3030473 - 3 months ago 6x
Python Question

Python append to an string element in a list

I'm fairly new to python. I want to know how can you append to a string element in a list cumulatively ?

list = ['1','2','3','4']
list2 = ['a','b','c','d']

I want a new list like this:

list3 = ['1a', '1b', '1c', '1d']

I've been running circles for possible answers. Help is much appreciated, thanks !


You can use map() and zip like so:

list = ['1','2','3','4']
list2 = ['a','b','c','d'] 

print map(lambda x: x[0] + x[1],zip(list,list2))


['1a', '2b', '3c', '4d']

Online Demo -