我有一个字符串说“aaabbccdaat”,所以下面的输出应该是A3B2C3D1A2T1。在
data = input("enter data ")
count =1
for steps in range(0,len(data)-1):
if (str(data[steps])==str(data[steps+1])):
count = count+1
else:
str(data[steps])=str(data[steps+1])
count=1
print ((str(count)+str(data[steps]))
我有一个字符串说“aaabbccdaat”,所以下面的输出应该是A3B2C3D1A2T1。 谢谢
我有一些方法可以分享,但我认为@Warren Weckesser的答案更好。:-)
有一种方法,使用^{} :
相关问题 更多 >
编程相关推荐