记录python语言的数组去重并输出

def find_duplicates(arr):
    seen = set()
    duplicates = []
    for num in arr:
        if num in seen:
            duplicates.append(num)
        seen.add(num)
    return duplicates

arr = ['1000223453', '1000227458', '1000223553', '1000223433', '1000223433', '1000227458', '1000227458', '1000223423', '1000223412', '1000223498']
duplicate_elements = find_duplicates(arr)
if duplicate_elements:
    print("数组中存在重复元素:", duplicate_elements)
else:
    print("数组中不存在重复元素。")

 

posted @ 2023-10-10 20:46  少年Dev  阅读(8)  评论(0编辑  收藏  举报