We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
In test case 1, my code output "that it is" as a first occured trigram. but expected output is "that i was".
I checked full testcase and found that my answer "that it is" is correct.
Are there any critical misunderstanding?
My code is following
#!/bin/python3importmathimportosimportrandomimportreimportsysdeffind_ngram(s,n):windowsize=n#iftrigramthen3#uppercases shift lowercases#. and \n shift <EOS> and <EOP>s=s.lower().replace("."," <EOS>").replace("\n"," <EOP> ")s_list=s.split()ngram_list=[]forstinrange(len(s_list)-windowsize+1):#From the front of document, first occured ngrams append to ngram_list.#find a ngram which already listed, return the ngram.ngram=" ".join(s_list[st:st+windowsize])ifngraminngram_list:returnngramelif"<EOP>"inngramor"<EOS>"inngram:#ngram which contains end signs ignorecontinueelse:ngram_list.append(ngram)returnngram_list[0]if__name__=='__main__':s=""forlineinsys.stdin:s+=lineprint(find_ngram(s,3))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
The Trigram
You are viewing a single comment's thread. Return to all comments →
Hi, help me about my problem.
In test case 1, my code output "that it is" as a first occured trigram. but expected output is "that i was". I checked full testcase and found that my answer "that it is" is correct.
Are there any critical misunderstanding?
My code is following