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.
#!/bin/python3importmathimportosimportrandomimportreimportsysfromcollectionsimportCounterif__name__=='__main__':# Sample large texttext=sys.stdin.read()pattern=r'[\r\n]'cleaned_text=re.sub(pattern,'',text)pattern=r'(?=(\b[a-z]+\s[a-z]+\s[a-z]+\b))'# Find all matchesmatches=re.findall(pattern,cleaned_text.lower())#print(matches)# Count the number of matches using Countermatch_counts=Counter(matches)#get the first value with highest numberresult=""max_num=0formatch,countinmatch_counts.items():#print(match, max_num, count)ifmax_num<count:result=matchmax_num=countprint(result.strip())
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 →