hackerrank solutions The first line of input contains the original string. The next line contains the substring.
import re
def count_substring(string,sub_string)
count = re.findall('(?='+sub_string+')',string)
return len(count)
hackerrank solutions The first line of input contains the original string. The next line contains the substring.
import re
def count_substring(string,sub_string)
count = re.findall('(?='+sub_string+')',string)
return len(count)
find a string hackerrank solution
#(method 1)
import re
def count_substring(string,sub_string)
count = re.findall('(?='+sub_string+')',string)
return len(count)
# (method 2) lengthy but easier for beginners
def count_substring(string, sub_string):
zero=0
astring=string + "@"
sub_count=0
count=0
for i in range (len(astring)-1):
if astring[i]==sub_string[0]:
for j in range(1,len(sub_string)):
if astring[i+j]==sub_string[j]:
sub_count+=1
elif astring[j+i]=='@':
break
if sub_count==len(sub_string)-1:
count+=1
sub_count=0
return count
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us