fruits = ['banana', 'apple', 'orange', 'mango', 'apple', 'pears', 'mango', 'cherry', 'apple']
uniques = set(fruits)
print(uniques)
def removeDuplicate(input):
secondList = []
for item in fruits:
if item not in secondList:
secondList.append(item)
return secondList
newList = removeDuplicate(fruits)
print(sorted(newList))
两者都删除了所有重复项并提供了新列表
答案 0 :(得分:0)
一个简单的功能应该起作用。类似于user:sacul发布的内容。
def remove_dup(my_list):
return list(set(my_list))
fruits = ['banana', 'apple', 'orange', 'mango', 'apple', 'pears', 'mango', 'cherry', 'apple']
remove_dup(fruits)
答案 1 :(得分:0)
prog_langs = ['C', 'C++', 'C#', 'Java', 'Python', 'C', 'PHP', 'C', 'Java']
no_dup_prog_list = [i for i in set(prog_langs)]
print(no_dup_prog_list)