我有一串字母:x = "ABCDE"
我有一个包含另一组字母的字符串: y = "VWXYZ"
我一直试图解决的想法是获取原始字符串 x,并将第二个字符串 y 中第一个字母(“V”)的所有实例读取到 x 的第一个位置。然后用所有字母 y 对 x 的所有位置重复此操作。
尝试了几个不同的循环,但很难做到这一点。
for i in range(len(x)):
print (x[i])
replaced = False
for z in range(len(y)):
x.replace(x[0],y[0])
输入字符串:
x = "ABCDE"
y = "VWXYZ"
理想情况下,结果将在新行上打印每个序列。期望的结果:
"ABCDE" # starting sequence
"VBCDE" # replace first position in x with first position in y
"WBCDE" # replace first position in x with second position in y
"XBCDE" # replace first position in x with third position in y
"YBCDE"
"ZBCDE" # replace first position in x with fifth position in y
"AVCDE" # replace second position in x with first position in y
"AWCDE" # replace second position in x with second position in y
.......
"ABCDZ" # This would be the final sequence in the series.
所以基本上我希望在新行上生成更改序列的字符串。
人到中年有点甜
慕尼黑5688855
慕斯王
相关分类