记录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("数组中不存在重复元素。")
本文来自博客园,作者:少年Dev,转载请注明原文链接:https://www.cnblogs.com/yaodun55/p/17755701.html