Quote:
I have tried in python but it is applicable only for when x and y are same.
Because you are swapping x and y, sometimes x is used as row, sometimes it is a column, and vice versa for y.
You need to choose which one is a row number and the other a column number and not change in middle of code.