Find a string one more one liner, though less efficient than yours. return[string[x:x+len(sub_string)]forxinrange(len(string)-len(sub_string)+1)].count(sub_string) i(len(string)))if(string[i:i+len(sub_string)]==sub_string))summ+=1...
1if__name__=='__main__':2n =int(input())3arr =map(int, input().split())4print(sorted(list(set(arr)))[-2])
For every test case, count and print (on a new line) the number of digits in N that are able to evenly divide N. Sample Input 2 12 1012 Sample Output 2 3 Explanation The number 12 is broken into two digits, 1 and 2. When 12 is divided by either of those digits, the calculation...
How to install Python in Windows How to reverse a string in Python How to read CSV file in Python How to run Python Program How to take input in Python How to convert list to string in Python How to append element in the list How to compare two lists in Python How to convert int ...
main.go:4:2: package boo is not in GOROOT (C:\Program Files\Go\src\boo) We can see that: go build and go install find the match directories, not source files, so we have to put the boo.go under the boo folder. Normally, when we want to import a package, follow these two ste...
Find a string defcount_substring(string,sub_string):counter,sum=0,0for_inrange(0,len(string)):ifmatcher(string[counter:(len(sub_string)+counter)],sub_string):sum=sum+1counter=counter+1returnsumdefmatcher(sliced_str,sub_string):returnsliced_str==sub_string...
Find a string Using List Comprehension: string, substring = (input().strip(), input().strip()) print(sum([ 1 for i in range(len(string)-len(substring)+1) if string[i:i+len(substring)] == substring]))
Find a string I think this solution could work, but in my opinion it's a bit unoptimized. Let's say in the sample test case: 'ABCDCDC' 'CDC', what your code does is that: s[0:0+3], s[1:1+3], s[2:2+3], ..., s[7:7+3]. The s[5:5+3] up to s[7:7+3] ...
Find a string This is my code, why you need two for loops and make this complex? This is my code: string, substring = (input().strip(),input().strip) count = 0 for i in range(0, len(string)-len(substring)+1): if string[i:i+len(substring)]==substring: count+=1 return ...