Python : Problem recreating replace function