MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / count_substring

Function count_substring

Hackerrank_problems/Find_a_String/Solution.py:8–18  ·  view source on GitHub ↗
(string, sub_string)

Source from the content-addressed store, hash-verified

6"""
7
8def count_substring(string, sub_string):
9 end=len(sub_string)
10 c=0
11 for i in range(len(string)):
12 #if starting character of substring is found in i-th position of string
13 if(string[i]==sub_string[0]):
14 """if all the characters from i-th position to i+length of substring
15 are same as thecharacters in the substring"""
16 if(string[i:i+end]==sub_string):
17 c=c+1 #increment counter by 1
18 return c
19
20if __name__ == '__main__':
21 #strip() is used to remove leading and trailing blank spaces

Callers 1

Solution.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected