>>> sn = [['1230','1'],['1230','2'],['1230','3'],['1230','4'],['2345','1'],['2345','2'],['2345','3'],['1111','1'],['1111','2'],['1111','3'],['1111','4'],['1111','5'],['2222','1'],['2222','2'],['2222','3'],['6547','1'],['6547','2'],['6547','3'],['9852','1'],['9852','2']]
>>> unit = []
>>> unit2=[]
>>> s = 0
>>> z = []
>>> for i in sn:
... n = i[1]
... unit.append(i[0])
... while i[0] not in unit:
... unit.append(i[0])
... break
...
>>> for x in unit:
... for y in sn:
... while s >= 3:
... if [y[0]] == z:
... s = s+1
... elif [y[0]] != z:
... s = 0
... break
... while x == y[0] and s < 2:
... unit2.append(y)
... z = [y[0]]
... break
... s =s+ 1
...
>>> print(unit2)
[['1230', '1'], ['1230', '2'], ['1230', '1'], ['1230', '1'], ['1230', '1'], ['2345', '1'], ['2345', '2'], ['1111', '1'], ['1111', '2'], ['2222', '1'], ['2222', '2'], ['6547', '1'], ['6547', '2'], ['9852', '1'], ['9852', '2']]
问题已解决 ,麻烦各位了! |