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]]

你可能感兴趣的:(python)