您的位置:首页 > 编程语言 > Python开发

[Python] for.. not in.. Remove Deduplication

2017-11-21 14:52 323 查看
Write a function,
remove_duplicates
that takes a list as its argument and returns a new list containing the unique elements of the original list. The elements in the new list without duplicates can be in any order.

Suggested test cases: Try an input list with no duplicate elements. The output list should be the same size as the original list. Try a small input list with a known number of unique entries, and some duplicates. Verify that the list without duplicates has the correct length.

def remove_duplicates(source):
target = []

for element in source:
if element not in target:
target.append(element)

return target
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐