def rreplace(string,str,new_str,max=1): string=string[::-1] str=str[::-1] new_str=new_str[::-1] return string.replace(str,new_str,max)[::-1]