UK and US: Part 2

  • + 0 comments
    import re
    
    content = ''
    for _ in range(int(input())):
        content += input() + ' '
        
    for _ in range(int(input())):
        uk = input()
        us = uk.replace('our', 'or')
        pattern = f'\\b({uk}|{us})\\b'
        print(len(re.findall(pattern, content)))