这很简单,只是我做不到!在这个例子中,我想要的是把下面的字符串分成相同字母的块,例如在下面的例子中:test = "AAATGG",会被分成"AAA","T","GG"。我尝试了不同的方法,下面是一个例子。我需要帮助。
我知道的思路是遍历字符串,如果下一个字母和当前字母相同,继续进行,否则,分割并打印,重新开始,我只是无法正确实现它。
test = "AAATGG"
TestDict = {}
for index,i in enumerate(test[:-1]):
string = ""
if test[index] == test[index+1]:
string = i + test[index]
else:
break
print string