的,我只是与Python开始,我必须定义一个函数来检查多少字符串列表中有超过2个字符或有他们的第一个和最后一个字符相同:字符串索引超出范围的错误蟒蛇
def match_ends(words):
count=0
for w in words:
if len(w)>=2:
count+=1
elif w[0]==w[-1]:
count+=1
return count
我得到一个错误消息说:
elif w[0]==w[-1]:
IndexError: string index out of range
这是什么意思?如何纠正?