human
What is a code to delete an element from array ( Using two traversals and one traversal ) and the other steps required given the following:
Delete an element from array ( Using two traversals and one traversal ) | This function removes an element x from arr [ ] and returns new size after removal ( size is reduced only when x is present in arr [ ].
Search x in array.
If x found in array.
reduce size of array and move all elements on space ahead.
Driver Code.
Delete x from arr [ ]"
How can the above be solved in Python?
assistant
#Here is code to delete an element from array ( Using two traversals and one traversal ) and the other steps required.
 def deleteElement ( arr , n , x ) :
	for i in range ( n ) :
		if ( arr [ i ] == x ) :
			break
	if ( i < n ) :
		n = n - 1 ;
		for j in range ( i , n , 1 ) :
			arr [ j ] = arr [ j + 1 ]
	return n
if __name__ == ' _ _ main _ _ ' :
	arr = [ 11 , 15 , 6 , 8 , 9 , 10 ]
	n = len ( arr )
	x = 6
	n = deleteElement ( arr , n , x )
	print ( " Modified ▁ array ▁ is " )
	for i in range ( n ) :
		print ( arr [ i ] , end = " ▁ " )