How to concatenate strings in different lists

Joonas Liik liik.joonas at gmail.com
Wed Nov 23 12:53:18 EST 2016


On 23 November 2016 at 19:40, Daiyue Weng <daiyueweng at gmail.com> wrote:
> Hi, I am wondering how to concatenate corresponding strings in two lists,
> assuming that the lists are of same length, e.g.
>
> val_1 = ['a', 'b', 'c']
> val_2 = ['A', 'B', 'C']
>
> # concatenate corresponding strings in 'val_1' and 'val_2'
> # and put results in another list 'val' so that
> # val = ['aA', 'bB', 'cC']
>
> cheers
> --
> https://mail.python.org/mailman/listinfo/python-list

one way to do it:

val = [''.join(pair) for pair in zip(val_1, val2)]



More information about the Python-list mailing list