You should be able to do a search and replace.
:%s/^\(\s*\)#\(\s*pdb.set_trace()\)/\1\2/ To un-comment and
:%s/^\(\s*\)\(pdb.set_trace()\)/\1#\2/ To re-comment.
This is done by using back-references. Anything matched in between memory parentheses \(\) can be recalled by using a back-reference (\1 and \2 in this case).