Advertisement
here2share

# substring_swap.py

Nov 3rd, 2018
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.21 KB | None | 0 0
  1. # substring_swap.py
  2.  
  3. def subswap(t,a,z):
  4.     if '{}' not in t:
  5.         for x in a,z: t = t.replace(x,'{}')
  6.         return t.format(z,a)
  7. 0
  8. s =  "123 AAA 456 ZZZ 789 (from AAA-to-ZZZ)"
  9. r = subswap(s,' AAA ',' ZZZ ')
  10.  
  11. print r
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement