ITeye博客

python切割

lfc_jack · 2018-02-07 22:53 · python切割集合里面相同的元素到一个集合里面 · 编程语言 · Python · Markdown



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)


#运行结果: , , , , , , , , , ]

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。