Elements that occurred only once in the array | Python3 implementation to find elements that appeared only once ; Function to find the elements that appeared only once in the array ; Store all the elements in the map with their occurrence ; Traverse the map and print all the elements with occurrence 1 ; Driver code
import math as mt NEW_LINE def occurredOnce ( arr , n ) : NEW_LINE INDENT mp = dict ( ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT if arr [ i ] in mp . keys ( ) : NEW_LINE INDENT mp [ arr [ i ] ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT mp [ arr [ i ] ] = 1 NEW_LINE DEDENT DEDENT for it in mp : NEW_LINE INDENT if mp [ it ] == 1 : NEW_LINE INDENT print ( it , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT arr = [ 7 , 7 , 8 , 8 , 9 , 1 , 1 , 4 , 2 , 2 ] NEW_LINE n = len ( arr ) NEW_LINE occurredOnce ( arr , n ) NEW_LINE