Lonely Integer

  • + 0 comments
    def lonelyinteger(a): 
        # Write your code here
        
        count_dict = {} # Initialize an empty dictionary
        for item in a:
            if item in count_dict:
                count_dict[item] += 1  
                # Increment the count if item is already in dictionary
            else:
                count_dict[item] = 1   
                # Add the item with count 1 if it's not in the dictionary
        return [key for key, value in count_dict.items() if value == 1]
        
        
    if __name__ == '__main__':
        fptr = open(os.environ['OUTPUT_PATH'], 'w')
    
        n = int(input().strip())
    
        a = list(map(int, input().rstrip().split()))
    
        result = lonelyinteger(a)
    
        fptr.write(' '.join(map(str,result)) + '\n')
    
        fptr.close()