How do you fuse string items from two lists into new elements of a new list?

639 Views Asked by At

I am working with a set of numbers as strings, and I need to put them together but NOT add/subtract them. Essentially I am working with this:

a = ['12', '34', '56', '78']
b = ['78', '56', '34', '12']

And I need:

c = ['1278', '3456', 5634', '7812']
2

There are 2 best solutions below

0
On

Considering the above case you mentioned, you can simply do this as follows(assuming both the input arrays are of same length):

for (int i=0; i<a.length; i++)
{
    c[i]=(a[i]*100)+b[i];
}

Note: This is only for the example case you mentioned.

0
On

Zip the two lists, and then concatenate the two strings in each element:

c = [x + y for x, y in zip(a, b)]