列表去除重复的值

 1 l = [1,1,2,3,4,5,4]
 2 #第一种方法,采用集合
 3 print(list(set(l)))
 4 
 5 #第二种方法采用排序
 6 d = []
 7 t = sorted(l)
 8 i = 0
 9 while i < len(t):
10     if t[i] not in d:
11         d.append(t[i])
12     else:
13         i+=1
14 print(d)
15 
16 #第三种方法
17 r = []
18 for x in l:
19     if x not in r:
20         r.append(x)
21 print(r)
人生的旅途,前途很远,也很暗。然而不要怕,不怕的人的面前才有路。
原文地址:https://www.cnblogs.com/ymany/p/9287701.html