About swap, in C++, we can swap two by std::swap(x, y);. x and y are passed into swap as reference.
swap
std::swap(x, y);
x
y
reference
But
Python passes by pointer.
Simpler swap:
x, y = y, x