删除列表中重复值,重复值保留一个

来源:互联网 发布:php公开课 编辑:程序博客网 时间:2024/05/17 04:42
#删除列表中的重复的值,保留重复值的第一个值s=[1,2,3,2,9,2,4,8,3,5,5,6,3,8,3,6,7,8]print(s)#print(l.count(9))i=0while i<len(s):      if s.count(i)>1:            pos=s.index(s[i])            print("pos:",pos)            temp1=s[:pos+1]            temp2=s[pos+1:]            j=0            while j<len(temp2):                  if temp2[j]==s[i]:                        temp2.pop(j)                        j=j-1                  j=j+1            s=temp1+temp2      i=i+1print(s)

原创粉丝点击