We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 879ca6c commit 62c7093Copy full SHA for 62c7093
1 file changed
Strings/Findastring.py
@@ -4,20 +4,21 @@
4
Domain : Python
5
Author : Ahmedur Rahman Shovon
6
Created : 15 July 2016
7
+Updated : 08 February 2023
8
Problem : https://www.hackerrank.com/challenges/find-a-string/problem
9
"""
10
11
12
def count_substring(string, sub_string):
- return sum(
13
- string[i : i + len(sub_string)] == sub_string
14
- for i in range(len(string) - len(sub_string) + 1)
15
- )
+ count_sub_string = 0
+ for i in range(len(string) - len(sub_string) + 1):
+ if string[i : i + len(sub_string)] == sub_string:
16
+ count_sub_string += 1
17
+ return count_sub_string
18
-
-if __name__ == "__main__":
19
+if __name__ == '__main__':
20
string = input().strip()
21
sub_string = input().strip()
22
+
23
count = count_substring(string, sub_string)
24
print(count)
0 commit comments