mfgnik May 31st, 2020 865 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- import re
- s = input()
- regex = r'\w+, \w+ (and|or) \w+'
- ends = 
- for match in re.finditer(regex, s):
- ends.append(s.rfind('and', match.start(), match.end()) + 1 or s.rfind('or', match.start(), match.end()) + 1)
- ends[-1] -= 2
- s_new = 
- for i in range(len(ends) - 1):
- s_new.append(s[ends[i]:ends[i + 1]])
RAW Paste Data