删除列表中的重复元素
def remove_duplicates(thy_list):
my_set = set(thy_list)
my_list = list(my_set)
return my_list
if __name__ == '__main__':
print(remove_duplicates([1, 1, 2, 2, 6, 5, 4, 9, 8, 9, 8]))
print(remove_duplicates([1, 3, 6, 9, 12, 12, 9, 6, 3, 1]))
找出列表中的重复元素
def find_duplicate_elements(thy_list):
thy_dict = {}
my_list = []
for i in thy_list:
if i in thy_dict:
thy_dict[i] += 1
else:
thy_dict[i] = 1
for key, value in thy_dict.items():
if value > 1:
my_list.append(key)
return my_list
if __name__ == '__main__':
print(find_duplicate_elements([1, 1, 2, 2, 6, 5, 4, 9, 8, 9, 8]))
print(find_duplicate_elements([1, 3, 6, 9, 12, 12, 9, 6, 3]))