user3030473 user3030473 - 1 year ago 112
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 !

Answer Source

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 -

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download