我想比較字符串中的下列字符,如果它們相等,請提高計數器。 用我的示例代碼,我總是得到與第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