a simple counting variable should do the trick: define a the variable with value zero (i.e. i = 0) before sorting and then increment (i+=1 )whenever you are swapping numbers.
i = 0
i+=1