s='aabbcddc'
要求輸出 2,2,4
s = 'aabbcddc'
dic = {}
lis = []
new_start = 0
for index,i in enumerate(s):
if index <= new_start:#如過小於上次的結束值,跳過
continue
else:
start = index
start_value = i
max_index = []#記錄同個字符的最長長度
for index0,i0 in enumerate(s):
if i0==start_value:
max_index.append(index0)
print(max(max_index)-min(max_index)+1)#輸出距離差
new_start=max(max_index)