Skip to content

Instantly share code, notes, and snippets.

@codeperfectplus
Created September 8, 2023 05:54
Show Gist options
  • Select an option

  • Save codeperfectplus/883b1d8c5e0e9bc5c7d0b7d512794366 to your computer and use it in GitHub Desktop.

Select an option

Save codeperfectplus/883b1d8c5e0e9bc5c7d0b7d512794366 to your computer and use it in GitHub Desktop.
import re
def substitute_text_in_string(text: str):
"""
Substitute text in string
&& -> and
|| -> or
change only if there are spaces around
"""
pattern = r'(?<=\s)&&(?=\s)|(?<=\s)\|\|(?=\s)'
output = re.sub(pattern, lambda x: 'and' if x.group() == '&&' else 'or', text)
print(output)
if __name__ == '__main__':
n = int(input())
text = ''
for _ in range(n):
text += input() + '\n'
substitute_text_in_string(text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment