1
この宿題に問題があります。 文字列中の連続する「特殊記号」の最大数を返す
def symbol_count(s:str): -> int
"""Return the largest number of consecutive "special symbols" in the
string s.
>>> symbol_count(’c0mput3r’)
0
>>> symbol_count(’H! [here’)
1
>>> symbol_count(’h3!!&o [email protected]#’)
3
"""
lst = []
count = 0
for i in range(len(s)-1):
if s[i] in SPECIAL_SYMBOLS:
count +=1
if s[i+1] not in SPECIAL_SYMBOLS:
lst.append(count)
count = 0
else:
count += 1
if lst == []:
return 0
return max(lst)
SPECIAL_SYMBOLS = '[email protected]#$%^&*()_+=[]?/'
ありがとうございました!本当にそこに私を救った。 – DWCY