qt=[1,1, 2,2, 2, 3,3,3,3, 4, 4, 5, 5, 6,6,6,6,6,6]
qt=[1,1,0, 2,2, 2, 3]
qts=[]
count=1
maxcount=[]
maxcount.append(count)
ind=[10,11,12,13,14,15,16]
inds=[]
for i in range(len(qt)-1):
if qt[i]!=qt[i+1]:
maxcount.append(count)
inds.append(ind[i])
qts.append(qt[i])
else:
count+=maxcount[-1]
maxcount.append(count)
inds.append(ind[i])
qts.append(qt[i])
count=1
inds.append(ind[-1])
qts.append(qt[-1])
结果:
print(qt)
print(maxcount)
print(inds)
print(ind)
print(qts)
[1, 1, 0, 2, 2, 2, 3]
[1, 2, 1, 1, 2, 3, 1]
[10, 11, 12, 13, 14, 15, 16]
[10, 11, 12, 13, 14, 15, 16]
[1, 1, 0, 2, 2, 2, 3]