Sort by

recency

|

303 Discussions

|

  • + 0 comments
    1. import re
      1. for i in range(int(input())):
    2. i = input()
    3. i=re.sub(r"(?<= )&&(?= )","and",i)
    4. i=re.sub(r"(?<= )||(?= )","or",i)
    5. print(i)
  • + 0 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

  • + 0 comments
    import re
    N = int(input())
    text = "\n".join(input() for _ in range(N))
    print(re.sub(r'(?<=\s)&&(?=\s)', 'and', re.sub(r'(?<=\s)\|\|(?=\s)', 'or', text)))
    
  • + 0 comments
    import os, sys, re
    
    text = sys.stdin.read()
    pattern = r"(?<=\s)(&{2}|[|]{2})(?=\s)"
    
    def modified_match(match_object):
    
        if match_object.group() == '&&':
            return 'and'
        else:
            return 'or'
    
    text = re.sub(pattern, modified_match, text)
    print(os.linesep.join(text.splitlines()[1:])) #removes the line count at line n°1
    
  • + 0 comments
    import re
    
    n = int(input())
    pattern = r'(?<= )(&{2}|\|{2})(?= )'
    func = lambda x: 'and' if x.group() == '&&' else 'or'
    
    for _ in range(n):
        print(re.sub(pattern, func, input()))