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

猜你喜欢

转载自lfc-jack.iteye.com/blog/2410510
今日推荐