Change x.sort() by sorted(x) as function return
Comment about the solution added
Comment about the solution added
Change '=' by deepcopy(), and add absolute value to the result, so it give us the actual difference
Comment about the solution added
Order of the parameters of trapz() changed for trapz(y,x)
Comment about the solution added
Size of the step changed
Graphic corrected acording to the modifications of the problem