Python 14.remove_duplicates

write a function remove_duplicates that takes in a list and removes elements of the list that are the same.
DOn't remove every occurrence ,since you need to keep a single occurrence of a number.
Do not modify the list you take as input! instead,**return ** a new list.
Hint:
the easiest way to approach this problem is to create a new list in your function,loop through your new list if the current item is not already contained in your new list.Using the a not in b syntax might help you here.

def remove_duplicates(n):
x = []
for i in n:
if i not in x:
x.append(i)
return x

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容