human
Give me a code to unique element in an array where all elements occur K times except one and the other steps required given the following:
Unique element in an array where all elements occur K times except one | Set 2 | Function that find the unique element in the array arr [ ].
Store all unique element in set.
Sum of all element of the array.
Sum of element in the set.
Print the unique element using formula.
Driver Code.
Function call"
How can the above be solved in Python?
assistant
#Here is code to unique element in an array where all elements occur K times except one and the other steps required.
 def findUniqueElements ( arr , N , K ) :
	s = set ( )
	for x in arr :
		s . add ( x )
	arr_sum = sum ( arr )
	set_sum = 0
	for x in s :
		set_sum += x
	print ( ( K * set_sum - arr_sum ) // ( K - 1 ) )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 12 , 1 , 12 , 3 , 12 , 1 , 1 , 2 , 3 , 2 , 2 , 3 , 7 ]
	N = len ( arr )
	K = 3
	findUniqueElements ( arr , N , K )