Python 3.x 我想得到一个结果ababaaa,如果变量t中没有更多的字符混合,代码将是错误的 我想让每个变量的每个字符像“ababaaa”一样混合,如果没有更多的字符了, `s= "aaaaaa" t= "bb" def func():

Python 3.x 我想得到一个结果ababaaa,如果变量t中没有更多的字符混合,代码将是错误的 我想让每个变量的每个字符像“ababaaa”一样混合,如果没有更多的字符了, `s= "aaaaaa" t= "bb" def func(): ,python-3.x,Python 3.x,我想得到一个结果ababaaa,如果变量t中没有更多的字符混合,代码将是错误的 我想让每个变量的每个字符像“ababaaa”一样混合,如果没有更多的字符了, `s= "aaaaaa" t= "bb" def func(): string ="" for i in range(3): string=string+s[i]+t[i] print(string) func()` # c

我想得到一个结果ababaaa,如果变量t中没有更多的字符混合,代码将是错误的 我想让每个变量的每个字符像“ababaaa”一样混合,如果没有更多的字符了,
     `s= "aaaaaa"
     t= "bb"
     def func():
        string =""
        for i in range(3):
          string=string+s[i]+t[i]  
          print(string)
     func()`
# combine the following strings, starting with string a, interleave
# character for character, and fill the rest of the string with the content
# of the longest string, using "list slicing" method
a = "aaaaaa"
b = "bb"

# create a list of empty strings `['']` with a length 
# equal to the maximum length of the longest string 
# `(len(a)|len(b))*2` times two
result_list = [''] * ((len(a) | len(b)) * 2)

# fill every second element `[::2]` with the elements of 
# string a, to the maximum lenght of the lenght 
# of string a times two `[:(len(a)*2):]`, starting at position 0 `[0::]`
result_list[0:(len(a)*2):2] = a

# fill every second element with the elements of 
# string b, to the maximum lenght of the lenght 
# of string b times two, starting at position 1
result_list[1:(len(b)*2):2] = b

# join the elements of the string list toghether
# to get a string as result
result_string = ''.join(e for e in result_list)

print(result_string)