Python Replace String Using Sedimentation