The British and American Style of Spelling

  • + 0 comments
    import re
    
    b = []
    for _ in range(int(input())):
        a = input()
        b.extend(re.findall(r"\b[a-zA-Z]+(?:ze|se)\b", a))
    
    c = int(input())
    queries = [input().strip() for _ in range(c)]
    
    for q in queries:
        british = q[:-2] + "se"  
        count = b.count(q) + b.count(british)
        print(count)