Most pythonic way to interleave two strings

前端 未结 14 1097
暗喜
暗喜 2020-11-27 14:34

What\'s the most pythonic way to mesh two strings together?

For example:

Input:

u = \'ABCDEFGHIJKLMNOPQRSTUVWXYZ\'
l = \'abcdefghijklmnopqrst         


        
14条回答
  •  一整个雨季
    2020-11-27 15:17

    I like using two fors, the variable names can give a hint/reminder to what is going on:

    "".join(char for pair in zip(u,l) for char in pair)
    

提交回复
热议问题