def alltt_escape(s):
 xlat = {'{': '\\{', '}': '\\}', '\\': '\\textbackslash{}'}
 return re.sub('[\\\\{}]', (lambda mo: xlat[mo.group()]), s)

def alltt_escape ( s ) : xlat = { '{' : '\\{' , '}' : '\\}' , '\\' : '\\textbackslash{}' } return re . sub ( '[\\\\{}]' , ( lambda mo : xlat [ mo . group ( ) ] ) , s )
replace backslash and braces with their escaped equivalents .