Sort by

recency

|

298 Discussions

|

  • + 0 comments
    import re
    
    n = int(input())
    
    for _ in range(n):
        
        line = input()
    
        line = re.sub(r'(?<= )&&(?= )', 'and', line)
    
        line = re.sub(r'(?<= )\|\|(?= )', 'or', line)
        
        print(line)
    
  • + 0 comments
    import re
    
    n = int(input())
    text = [input() for x in range(n)]
    pattern1 = re.compile(r'(?<= )&&(?= )')
    pattern2 = re.compile(r'(?<= )\|\|(?= )')
    
    for x in text:
        x = (re.sub(pattern1, "and", x))
        x = (re.sub(pattern2, "or", x))
    
        print(x)
    
  • + 0 comments
    import re
    for _ in range(int(input())):
        print(re.sub(r'(?<= )&&(?= )', 'and', re.sub(r'(?<= )\|\|(?= )', 'or', input())))
    
  • + 0 comments

    Managed to more or less fit all replacement logic into one line:

    import re
    
    n = int(input())
    for _ in range(n):
        print(re.sub(r"(?<= )\|\|(?= )", "or", re.sub(r"(?<= )&&(?= )", "and", input())))
    
  • + 0 comments
    import re
    n = int(input())
    s = "\n".join([input() for _ in range(n)])
    patern = r'(?<=\s)&&(?=\s)|(?<=\s)\|\|(?=\s)'
    print(re.sub(patern, lambda m: 'and' if m.group(0) == '&&' else 'or', s))