Most pythonic way to interleave two strings

前端 未结 14 1098
暗喜
暗喜 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:19

    I would use zip() to get a readable and easy way:

    result = ''
    for cha, chb in zip(u, l):
        result += '%s%s' % (cha, chb)
    
    print result
    # 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz'
    

提交回复
热议问题