Python: node & union find structure