Find a string

Sort by

recency

|

3377 Discussions

|

  • + 0 comments

    def count_substring(string, sub): count = 0 longsub = len(sub) compare = "" concidence = 0 for i in string: count += 1 compare += i

        if count == longsub:
            if compare == sub:
                concidence += 1
    
            compare = compare[1:]
            count -=1
    
    return concidence
    
  • + 0 comments

    return sum(string.startswith(sub_string,i) for i in range(len(string)-1))

  • + 0 comments
    def count_substring(string, sub_string):
        count = 0
        for i in range(0, len(string)-1):
            if string.startswith(sub_string, i):
                count += 1
    
        return count
    
  • + 0 comments
    def count_substring(string, sub_string):
        sub_len=len(sub_string)
        c=0
        for i in range(len(string)):
            if string[i :i+sub_len]==sub_string:
                c +=1
        return c
    
  • + 0 comments

    if sub_string[0] == sub_string[len(sub_string) - 1]: x = string.count(f"{sub_string}") + 1 return x else: x = string.count(f"{sub_string}") return x