SHARE
TWEET

multi replacements

DeaD_EyE Jan 1st, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def replace_text(text, replacements):
  2.     for old, new in replacements:
  3.         text = text.replace(old, new)
  4.         # text will be reassigned inside the function
  5.         # the text outside is not modified (call by reference)
  6.     # after all replacements, the changed text is returned by this function
  7.     return text
  8.  
  9. replacements = [
  10.     ("Зсбн","3 fM"), ("2сбн", "2 fM"),
  11.     ("3сбн", "3 fM"), ("4сбн", "4 fM"),
  12.     ("6сбн", "6 fM"), ("круг", "Runde"),
  13.     ("ряда", "mal"),
  14.     ]
  15.  
  16. text = "Зсбн‚ прибавка, 3сбн‚ (3с6н‚ прибавка)-3раза‚ 3сбн,Зсбн, прибавка-2раза=36сбн"
  17. print(text)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top