• + 1 comment

    This code passes only the first test case. Can't see anything wrong with the code or the pattern:

    import re
    
    sentences = "".join([input() for _ in range(int(input()))])
    words = [input() for _ in range(int(input()))]
    
    for w in words:
        regex = f"\\b{w}\\b"
        try:
            print(len(re.findall(regex, sentences)))
        except TypeError:
            print(0)