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
|
3387 Discussions
|
Please Login in order to post a comment
def count_substring(string, sub_string): count = 0 start = 0
if name == 'main': string = input().strip() sub_string = input().strip()
def count_substring(string, sub_string): count = 0 while sub_string in string : find = string.find(sub_string) string = string[find+1:] count += 1 return count
if name == 'main': string = input().strip() sub_string = input().strip()
This is a great challenge for practicing string manipulation and pattern matching! Counting the occurrences of a substring within a string is a useful skill, and traversing the string from left to right, 11 winner
Ya'll answers are complicated. I still used it for reference and this is what I came up with.
def count_substring(string, sub_string): counter = 0
if name == 'main': string = input().strip() sub_string = input().strip()