jmpark0118 / CODING_TEST_PRACTICE

0 stars 0 forks source link

Practice>Python>Regex and Parsing>Regex Substitution #103

Open jmpark0118 opened 3 years ago

jmpark0118 commented 3 years ago

image image image image

출처 : https://www.hackerrank.com/challenges/re-sub-regex-substitution/problem

jmpark0118 commented 3 years ago
import re

def modify_symbols(match):
    symbol = match.group(0)
    if symbol == '&&':
        return 'and'
    elif symbol == '||':
        return 'or'

if __name__ == '__main__':
    for i in range(int(input())):
        print(re.sub(r'(?<= )(&&|\|\|)(?= )', modify_symbols, input()))
jmpark0118 commented 3 years ago

import re

if __name__ == '__main__':
    for _ in range(int(input())):
        print(re.sub(r'(?<= )(&&|\|\|)(?= )', lambda x: 'and' if x.group() == '&&' else 'or', input()))