Python port for swap case problem.