• + 0 comments

    New to python. Here is my python 3 code. It passed all the tests.

    import re
    
    num = int(input())
    
    for i in range(num):
        line = input()
        line = re.sub('[^\w\s]', '', line)
        tokens = line.lower().split(' ')
        print(tokens.count('a'))
        print(tokens.count('an'))
        print(tokens.count('the'))
        pattern1 = '\d{2}/\d{2}/\d{4}'
        match1 = re.findall(pattern1, line)
        pattern2 = '\d{2}/\d{2}/\d{2}'
        match2 = re.findall(pattern2, line)
        months = '(January|Feburary|March|April|May|June|July|August|September|October|November|December|Jan|Feb|Mar|Apr|May' \
             '|Jun|Jul|Aug|Sep|Oct|Nov|Dec)'
        days = '(0?[1-9]|[1-2][0-9]|30|31|1st|2nd|3rd|[4-9]th|[1-2][0-9]th|30th|31st|21st|22nd)'
        pattern3 = days + '\s' + months + '(\s)(\d{4}|\d{2})'
        pattern4 = months + '\s' + days + '(\s)(\d{4}|\d{2})'
    
    	match3 = re.findall(pattern3, line)
    	match4 = re.findall(pattern4, line)
    	print(len(match1) + len(match2) + len(match3) + len(match4))
    
    	if i < (num-1):
    			input()