Merge two strings with alternate chars as output

后端 未结 5 1320
悲哀的现实
悲哀的现实 2021-01-17 01:53

I got the task to alternately combine the letters of two strings with the same length.

For example:

Inputstring 1: \"acegi\"

Inputstring 2: \"bdfhj\         


        
5条回答
  •  感情败类
    2021-01-17 02:00

    One can simply use map with join to get desired result:

    "".join(map(lambda x,y: x+y, astr, bstr))
    

    zip in not needed here since 2 strings/lists can be provided to map which has a lambda function that takes 2 arguments. Also, + symbol works to concatenate 2 strings here.

提交回复
热议问题