我想比较字符串中的下列字符,如果它们相等,请提高计数器。 用我的示例代码,我总是得到与第6行相关的TypErrors。 你知道问题出在哪里吗?在Python中比较字符串中的字符
谢谢!
def func(text):
counter = 0
text_l = text.lower()
for i in text_l:
if text_l[i+1] == text_l[i]:
print(text_l[i+1], text_l[i])
counter += 1
return counter
'对于text_l中的i:'迭代_individual个字符_,以便在每次迭代时输入(i)== str'。 – ForceBru