human
Give me a code to average of remaining elements after removing K largest and K smallest elements from array and the other steps required given the following:
Average of remaining elements after removing K largest and K smallest elements from array | Function to find average.
base case if 2 * k >= n means all element get removed.
first sort all elements.
sum of req number.
find average.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to average of remaining elements after removing K largest and K smallest elements from array and the other steps required.
 def average ( arr , n , k ) :
	total = 0
	if ( 2 * k >= n ) :
		return 0
	arr . sort ( )
	start , end = k , n - k - 1
	for i in range ( start , end + 1 ) :
		total += arr [ i ]
	return ( total / ( n - 2 * k ) )
if __name__ == " _ _ main _ _ " :
	arr = [ 1 , 2 , 4 , 4 , 5 , 6 ]
	n = len ( arr )
	k = 2
	print ( average ( arr , n , k ) )