Keep duplicates in a list in Python

后端 未结 4 1987
悲哀的现实
悲哀的现实 2021-01-12 01:00

I know this is probably an easy answer but I can\'t figure it out. What is the best way in Python to keep the duplicates in a list:

x = [1,2,2,2,3,4,5,6,6,7         


        
4条回答
  •  不思量自难忘°
    2021-01-12 01:06

    keepin' it simple:

    array2 = []
    aux = 0
    aux2=0
    for i in x:
        aux2 = i
        if(aux2==aux):
            array2.append(i)
        aux= i
    list(set(array2))
    

    That should work

提交回复
热议问题