while(i <= len(word_noSpaces)- 1):
count = 1
while word_noSpaces[i] == word_noSpaces[i+1]:
i = i + 1
count +=1
if i + 1 == len(word_noSpaces):
break
print(str(word_noSpaces[i]) + " " + str(count), end = "\n")
i+=1
print()
答案 0 :(得分:0)
请考虑以下内容:
import re
word_noSpaces="xyzccfjjkkkvbmbdfj"
for el in re.finditer(r"(.)\1+", word_noSpaces):
el=el[0]
print(el)
print(len(el))
它将打印所有重复的字符及其长度。
有关re
软件包的更多信息: