更新时间:2021-08-02 09:31:46
如果您只是想检查它是否包含重复项.一旦该函数找到出现多次的元素,它就会作为重复项返回.
If you simply want to check if it contains duplicates. Once the function finds an element that occurs more than once, it returns as a duplicate.
my_list = [1, 2, 2, 3, 4]
def check_list(arg):
for i in arg:
if arg.count(i) > 1:
return 'Duplicate'
print check_list(my_list) == 'Duplicate' # prints True