Sort by

recency

|

12 Discussions

|

  • + 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()
    
  • + 0 comments

    Can anyone please share python3 code for this? need help please.

  • + 1 comment

    I am using python3 and its working fine in my local setup. But its throwing some list index error.Looks like it is not splitting the sentences.

    Below are my sample code to split sentences into a list N = int(input()) data = input()

    sentences = data.split('\n\n')

    Is there any way to troubleshoot code in hackerank environment?

  • + 1 comment

    I solved this correctly in python-2 and got 9.88 as my score. I downloaded testcase1 and its output, and checked my result against the output, I discovered it only identified one date in paragraph 6 see pasted below. My code indentified 2 distinct dates in paragraph six i.e. July 2, 1776 and July 4.

    paragraph-6: "During the American Revolution, the legal separation of the Thirteen Colonies from Great Britain occurred on July 2, 1776, when the Second Continental Congress voted to approve a resolution of independence that had been proposed in June by Richard Henry Lee of Virginia declaring the United States independent from Great Britain.[4][5] After voting for independence, Congress turned its attention to the Declaration of Independence, a statement explaining this decision, which had been prepared by a Committee of Five, with Thomas Jefferson as its principal author. Congress debated and revised the wording of the Declaration, finally approving it on July 4."

  • + 1 comment

    About the second test case last text chunk, I only found 2 date after read it, why the answer should be 3?