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.
- Prepare
- Python
- Strings
- Find a string
- Discussions
Find a string
Find a string
Sort by
recency
|
3444 Discussions
|
Please Login in order to post a comment
def count_substring(string, sub_string): count1 = 0 count2 = 0 i=0 j=0
if name == 'main': string = input().strip() sub_string = input().strip()
Just to point out, there is a slight optimization in the loop. One can stop after len(s) - len(sub) + 1 since the remaining part of s at that point is shorter than the pattern to match and thus can't possibly match.
damn i couldve just sliced it 😠need more practice...