1 c=[1,1,1,1,2,2,2,3,3,4,4,4,4,4,5,5,5,] 2 a = [] 3 x = [] 4 for i in range(0,len(c)): 5 if i + 1 < len(c): 6 if c[i] == c[i + 1]: 7 x.append(c[i]) 8 else: 9 x.append(c[i]) 10 a.append(x) 11 x = [] 12 else: 13 x.append(c[len(c) - 1]) 14 a.append(x) 15 print(a)
运行结果:
[[1, 1, 1, 1], [2, 2, 2], [3, 3], [4, 4, 4, 4, 4], [5, 5, 5]]
时间: 2024-12-30 03:45:45