Python Set difference to find lost element from a duplicated array Last Updated : 28 Jul, 2022 Comments Improve Suggest changes Like Article Like Report Given two arrays which are duplicates of each other except one element, that is one element from one of the array is missing, we need to find that missing element. Examples: Input: A = [1, 4, 5, 7, 9] B = [4, 5, 7, 9] Output: [1] 1 is missing from second array. Input: A = [2, 3, 4, 5 B = 2, 3, 4, 5, 6] Output: [6] 6 is missing from first array. We have existing solution for this problem please refer Find lost element from a duplicated array. We can solve this problem quickly in python using Set difference logic. Approach is very simple, simply convert both lists in Set and perform A-B operation where len(A)>len(B). Implementation: Python3 # Function to find lost element from a duplicate # array def lostElement(A,B): # convert lists into set A = set(A) B = set(B) # take difference of greater set with smaller if len(A) > len(B): print (list(A-B)) else: print (list(B-A)) # Driver program if __name__ == "__main__": A = [1, 4, 5, 7, 9] B = [4, 5, 7, 9] lostElement(A,B) Output[1] Comment More infoAdvertise with us Next Article Python Set difference to find lost element from a duplicated array S Shashank Mishra Follow Improve Article Tags : Python DSA Arrays python-set Practice Tags : Arrayspythonpython-set Similar Reads Find lost element from a duplicated array Given two arrays that are duplicates of each other except one element, that is one element from one of the array is missing, we need to find that missing element. Examples: Input: arr1[] = {1, 4, 5, 7, 9} arr2[] = {4, 5, 7, 9}Output: 11 is missing from second array.Input: arr1[] = {2, 3, 4, 5} arr2[ 15+ min read Javascript Program for Find lost element from a duplicated array Given two arrays that are duplicates of each other except one element, that is one element from one of the array is missing, we need to find that missing element.Examples: Input: arr1[] = {1, 4, 5, 7, 9} arr2[] = {4, 5, 7, 9}Output: 11 is missing from second array.Input: arr1[] = {2, 3, 4, 5} arr2[] 4 min read Find missing elements from an Array with duplicates Given an array arr[] of size N having integers in the range [1, N] with some of the elements missing. The task is to find the missing elements. Note: There can be duplicates in the array. Examples: Input: arr[] = {1, 3, 3, 3, 5}, N = 5Output: 2 4Explanation: The numbers missing from the list are 2 a 12 min read How to Remove Duplicate Elements from NumPy Array In this article, we will see how to remove duplicate elements from NumPy Array. Here we will learn how to Remove Duplicate Elements from a 1-D NumPy Array and 2-D NumPy Array.Input1: [1 2 3 4 5 1 2 3 1 2 9] Output1: [1 2 3 4 5 9] Explanation: In this example, we have removed duplicate elements from 7 min read Count distinct elements in an array in Python Given an unsorted array, count all distinct elements in it. Examples: Input : arr[] = {10, 20, 20, 10, 30, 10} Output : 3 Input : arr[] = {10, 20, 20, 10, 20} Output : 2 We have existing solution for this article. We can solve this problem in Python3 using Counter method. Approach#1: Using Set() Thi 2 min read Like