python切割

来源:转载

def funThree(list01): newList = [] for i in range(0,len(list01)): count = len(newList) if count == 0: newList.append([list01[i]]) else: if list01[i] in newList[count-1]: newList[count-1].append(list01[i]) else: newList.append([list01[i]]) return newList#测试list01 = funThree([1,1,1,1,1,0,0,0,0,0,0,0,1,1,0,0,0,1,1,0,1,1,0,0,0,1,1,0])print(list01)
#运行结果:[[1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0], [1, 1], [0, 0, 0], [1, 1], [0], [1, 1], [0, 0, 0], [1, 1], [0]]

分享给朋友:
您可能感兴趣的文章:
随机阅读: