Created
September 8, 2023 05:54
-
-
Save codeperfectplus/883b1d8c5e0e9bc5c7d0b7d512794366 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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