Guest User

Untitled

a guest
Jul 20th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. bad_chars = {u"n": u" ", u"b": u" ", u"f": u" ", u"r": u" ", u"t": u" ", u"v": u" ", u"x00": u" "}
  2. bad_chars_table = dict((ord(k), v) for k, v in bad_chars.iteritems())
  3. translator = lambda s: s.translate(bad_chars_table)
  4. print translator(u"herenwetgo")
  5.  
  6. translator = lambda s: re.sub(r'[nbfrtvx00]', ' ', s)
  7.  
  8. translator = lambda s: reduce(lambda x, (from, to): x.replace(from, to), bad_chars.iteritems(), s)
  9.  
  10. def translator(s):
  11. for original, replacement in bad_chars.iteritems():
  12. s = s.replace(original, replacement)
  13. return s
  14.  
  15. print ''.join(map(lambda x: bad_chars.get(x, x), stri))
  16.  
  17. print ''.join(bad_chars.get(x, x) for x in stri)
  18.  
  19. bad_chars= {"newline":" ","n": " ", "b":" ", "f":" ", "r":" ", "t":" ", "v":" ", "x00":" "}
  20. stri = "a b stringn with t lots of v bad chars"
  21. print ''.join(bad_chars.get(x, x) for x in stri)
  22.  
  23. a string with lots of bad chars
  24.  
  25. replaced = reduce(lambda stri, r: stri.replace(r[0], r[1]), bad_chars.iteritems(), original)
  26.  
  27. stri.replace(r0[0], r0[1]).replace(r1[0], r1[1]).replace(...)
Add Comment
Please, Sign In to add comment