Lots of c++ code plus in place swapping in python