Traversing two strings at a time python

前端 未结 4 1169
悲&欢浪女
悲&欢浪女 2021-01-07 08:58

I have two strings and I want to print them one character at a time alternatively. Like say

s1 = \"Hi\"
s2 = \"Giy\"

for c,d in s1,s2:
    print c
    print         


        
4条回答
  •  梦毁少年i
    2021-01-07 09:29

    Use this function,

       def  mergeStrings(a, b):
            s = ''
            count = 0
            for i in range(min(len(a),len(b))):
                s+=a[i]
                s+=b[i]
                count+=1
            s+= a[count:] if len(a) > len(b) else b[count:]
            return s
    

提交回复
热议问题