You are viewing a single comment's thread. Return to all comments →
import re and_pattern = re.compile( r"(?<=[\s])[&&]{2}(?=[\s])" ) or_pattern = re.compile( r"(?<=[\s])[||]{2}(?=[\s])" )
for _ in range(int(input())): print( re.sub(and_pattern,'and', re.sub(or_pattern, 'or', input())) )
Could reduce it down, however it would make it less readable.
Sometimes fewer lines isn't better
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 and_pattern = re.compile( r"(?<=[\s])[&&]{2}(?=[\s])" ) or_pattern = re.compile( r"(?<=[\s])[||]{2}(?=[\s])" )
for _ in range(int(input())): print( re.sub(and_pattern,'and', re.sub(or_pattern, 'or', input())) )
Could reduce it down, however it would make it less readable.
Sometimes fewer lines isn't better