<p>嗨,我想写一个函数,可以告诉你有多少次不同的相邻字符退出字符串。i、 e LOLOLO有5次不同的相邻词。我试过很多次了,但每次我跑,我都会失败error:- line 5,在相邻的\u编号中
如果c!=字符串[i+1]:
索引器错误:字符串索引超出范围</p>
<pre><code>def adjacent_numbers(string):
count = 0
i = 0
for i,c in enumerate(string):
if c != string[i+1] :
count += 1
i += 1
return count
</code></pre>