You are viewing a single comment's thread. Return to all comments →
import re
def replace_operators(text): text = re.sub(r'(?<=\s)||(?=\s)', 'or', text) text = re.sub(r'(?<=\s)&&(?=\s)', 'and', text) return text
N = int(input()) text = "\n".join(input() for _ in range(N)) result = replace_operators(text) print(result)
Seems like cookies are disabled on this browser, please enable them to open this website
Regex Substitution
You are viewing a single comment's thread. Return to all comments →
import re
def replace_operators(text): text = re.sub(r'(?<=\s)||(?=\s)', 'or', text) text = re.sub(r'(?<=\s)&&(?=\s)', 'and', text) return text
N = int(input()) text = "\n".join(input() for _ in range(N)) result = replace_operators(text) print(result)