我被要求创建一个函数来计算字符串中顺序的字母数,因为我正在计时,这就是我的意思:
def count_letter(inString):
result = ''
count = 0
for l in xrange(0,len(inString)):
count += 1
if inString[l:l+1]!= inString[l+1:l+2]:
result += str(count) + inString[l:l+1]
count = 0
return result
inp_string = "llasssoooaappeeoaaa"
result = "2l1a3s3o2a2p2e1o3a"
如何将此功能改进为更像Python方式?