from copy import deepcopy
defcheckio(data:list)->list:"""
方法1:删除唯一的元素
list 使用remove循环删除中的元素,坑!
因为下标问题,要先复制一份list,然后循环主list,去删除复制list的元素
"""# data2 = deepcopy(data)# for li in data:# if data.count(li) == 1:# data2.remove(li)# return data2"""
方法2:判断如果元素是多个则取出
"""return[i for i in data if data.count(i)>1]if __name__ =="__main__":#These "asserts" using only for self-checking and not necessary for auto-testingassertlist(checkio([1,2,3,1,3]))==[1,3,1,3],"1st example"assertlist(checkio([1,2,3,4,5]))==[],"2nd example"assertlist(checkio([5,5,5,5,5]))==[5,5,5,5,5],"3rd example"assertlist(checkio([10,9,10,10,9,8]))==[10,9,10,10,9],"4th example"print("It is all good. Let's check it now")