Riju21

18_practice4_left_right_replace

Mar 27th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. # left - right replace
  2. #---------------------------------
  3.  
  4. x = ['0l77r3','0lr5']
  5. def check(m):     # function that operates left & right condition
  6.     strRepl = m.replace('', ' ')
  7.     toStr = str(strRepl)
  8.     toList = toStr.split(' ')
  9.     final = ''
  10.     for i,o in enumerate(toList):
  11.         if o == 'l':
  12.             getInd = toList.index(o)
  13.             toList[i] = o.replace(toList[getInd], toList[getInd - 1])
  14.         if o == 'r':
  15.             getInd = toList.index(o)
  16.             toList[i] = o.replace(toList[getInd], toList[getInd + 1])
  17.  
  18.     for i in toList:
  19.         final += i  
  20.     return final        
  21. for m in x:
  22.     print(check(m))
Advertisement
Add Comment
Please, Sign In to add comment