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
|
3452 Discussions
|
Please Login in order to post a comment
sliding through string looking using index and counting occurences + comments for debug
def count_substring(string, sub_string):
count = 0 for i in range(len(string) - len(sub_string)+1):
if string[i:i + len(sub_string)] == sub_string: count += 1 return count
def count_substring(string, sub_string): bonathan = list(string) chris = len(sub_string) mr_beats = [] timmy = 0
if name == 'main': string = input().strip() sub_string = input().strip()
hi guys this is my ans u can also use this to visualize better https://pythontutor.com/render.html#mode=display