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.
i solved this probelm by using findall and regular expression..
reg = r(?<=[\W]) + searching_word + (?=[\W])
:: \W represents non unicode characters... in this problem, playing a role of wrapper...
for ignoring '_'(underscore) and taking first and last word into consideration more conveniently, i made some tricks..
pre-processing::
1) deleting all the '_'s..
:: foo_bar --> foobar
2) putting '*' in first and last position..
:: foo foo foo -> *foo foo foo*
code ::
import re
n = int(input())
st = '\n'.join(['*'+input().strip().replace('_','')+'*' for _ in range(n)])
for _ in range(int(input())):
wd = input().strip()
reg = r'(?<=[\W])'+ wd +'(?=[\W])'
m = re.findall(reg,st)
print(len(m))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Find a Word
You are viewing a single comment's thread. Return to all comments →
i solved this probelm by using findall and regular expression..
for ignoring '_'(underscore) and taking first and last word into consideration more conveniently, i made some tricks..
pre-processing::
code ::