我是这种 python 语言的新手:我在以下 pgm 中显示列表中的唯一元素时遇到问题:以下是我的程序:
def unique_list(lst):
c = []
for i in lst:
if (lst.count(i)>=1) & i not in c:
c.append(i)
#print(c)
return c
print(unique_list([1,1,1,2,2,3,3,4,5]))
我收到的输出为:
[1,2,2,4]代替[1,2,3,4,5]
我认为 if stmt 中有一个错误……谁能解释一下我得到这个输出了吗?