def check_list(list_in):
list_new = set(list_in)
list_not = []
if len(list_in) != len(list_new):
for element in list_in:
if list_in.count(element) > 1 and element not in list_not:
list_not.append(element)
print(f"存在重复数据:{list_not}")
else:
print("不存在重复数据")
check_list([1, 2, 2, 2])
py001-检查列表中是否有重复元素
该代码定义了一个名为defcheck_list的函数,用于检查输入列表中是否存在重复元素,并打印出重复的数据。示例中使用[1,2,2,2]作为输入。
摘要由CSDN通过智能技术生成