#i couldnt find the difference in the code
>>> def match_ends(words):
# +++your code here+++
count=0
for string in words:
if len(string)>=2 and string[0]==string[-1]:
count=count+1
return count
>>> match_ends(['', 'x', 'xy', 'xyx', 'xx'])
2
>>>
>>> def match_ends(words):
# +++your code here+++
count=0
for string in words:
if string[0]==string[-1] and len(string)>=2:
count=count+1
return count
>>> match_ends(['', 'x', 'xy', 'xyx', 'xx'])
Traceback (most recent call last):
File "<pyshell#26>", line 1, in <module>
match_ends(['', 'x', 'xy', 'xyx', 'xx'])
File "<pyshell#25>", line 5, in match_ends
if string[0]==string[-1] and len(string)>=2:
IndexError: string index out of range
if len(string)>=2 and string[0]==string[-1]:
最初の関数と if string[0]==string[-1] and len(string)>=2:
2 番目の関数の if 条件を除いて、コードの違いを見つけることができませんでした。