SHARE
TWEET

Untitled

mfgnik May 31st, 2020 865 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import re
  2.  
  3. s = input()
  4. regex = r'\w+, \w+ (and|or) \w+'
  5. ends = [0]
  6. for match in re.finditer(regex, s):
  7.     ends.append(s.rfind('and', match.start(), match.end()) + 1 or s.rfind('or', match.start(), match.end()) + 1)
  8.     ends[-1] -= 2
  9. ends.append(len(s))
  10. s_new = []
  11. for i in range(len(ends) - 1):
  12.     s_new.append(s[ends[i]:ends[i + 1]])
  13. print(','.join(s_new))
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