我有一個列表中的項目序列。我想識別相同元素的運行並打印它們的起始和結束位置。例如,對於:確定重複列表項的運行
content=[c,c,c,c,f,f,f,f,c,c,b,b,b,b...]
我所要的輸出如:
1-4 c
5-8 f
9-10 c
等等等等。這是我到目前爲止有:
x=len(content)-1
i=0
y=0
z=0
for i in range(0,x):
if(content[i]==content[i+1]):
y=y+1
z=i-1
else:
print y
print content[z]
你能證明你在使用'if'並試圖'else'來解決這個問題? – TigerhawkT3
您能否提供您嘗試過的具體例子? – glls
X = LEN(內容) I = 0 對於i在(O,X): 如果(內容[I] ==內容[I + 1]): 否則: 打印i + 1的 – Arushi