• + 0 comments

    I have learn that in this case of situation, with "exactly 3 or 6" we can do {3}|{6}.

    Instead, we have to write twice the instruction, with firstly {6} (the biggest number), then {3} (the lowest number)

    Then, findall() occurences which respect this pattern (with # at the start obviously) and extend an output list to write every results at the end.

    Here the code :

    # Enter your code here. Read input from STDIN. Print output to STDOUT
    import re
    
    pattern = r"#([0-9A-Fa-f]{6}|[0-9A-Fa-f]{3})"
    
    N = int(input())
    output = list()
    for _ in range(N):
        current_line = input()
        
        if ":" in current_line:
            m = re.findall(pattern, current_line)
            if m:
                output.extend(m)
    
    
    for element in output:
        print(f"#{element}")