human
Give me a code to check if array can be sorted with one swap and the other steps required given the following:
Check if array can be sorted with one swap | A linear Python 3 program to check if array becomes sorted after one swap.
Create a sorted copy of original array.
Check if 0 or 1 swap required to get the sorted array.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to check if array can be sorted with one swap and the other steps required.
 def checkSorted ( n , arr ) :
	b = [ ]
	for i in range ( n ) :
		b . append ( arr [ i ] )
	b . sort ( )
	ct = 0
	for i in range ( n ) :
		if arr [ i ] != b [ i ] :
			ct += 1
	if ct == 0 or ct == 2 :
		return True
	else :
		return False
if __name__ == ' _ _ main _ _ ' :
	arr = [ 1 , 5 , 3 , 4 , 2 ]
	n = len ( arr )
	if checkSorted ( n , arr ) :
		print ( " Yes " )
	else :
		print ( " No " )