add swap nodes in pairs python version