def _sanitize_text_helper(text, valid_characters=valid_chars, character_map=mapped_chars, invalid_character='X'):
 out = []
 for c in text:
  if (c in valid_characters):
   out.append(c)
  elif (c in character_map):
   out.append(character_map[c])
  else:
   out.append(invalid_character)
 return ''.join(out)

def _sanitize_text_helper ( text , valid_characters = valid_chars , character_map = mapped_chars , invalid_character = 'X' ) : out = [ ] for c in text : if ( c in valid_characters ) : out . append ( c ) elif ( c in character_map ) : out . append ( character_map [ c ] ) else : out . append ( invalid_character ) return '' . join ( out )
restricts the characters that are allowed in a string .