Replace A Pattern In Python Using And In If Statement