You are viewing a single comment's thread. Return to all comments → yashpalsinghdeo1 4 years ago here is problem solution in python 2 and python 3 programming. https://programs.programmingoneonone.com/2021/01/hackerrank-find-a-string-solution-python.html -8|ParentPermalink tamylv_pb 4 yea...
string[0:0+len(sub_string)] after simplyfying we get string[0:3] now our program will scan string's content and if string[0:3]==sub_string then only counter will increase otherwise it will go to next position I.E. string[1:4]==sub_string(bcd!=cdc) counter will not increse stri...
Find a string Somewhat similar but more efficient defcount_substring(string,sub_string):count=0;foriinrange(len(sub_string),len(string)+1):if(string[i-len(sub_string):i]==sub_string):count+=1returncount count_substring():=0foriinrange(0,len(string)):if(string[i:i+len(sub_string)...
Find a string check this def count_substring(string, sub_string): count =0 for i in range(0,len(string)-len(sub_string)+1): try: if string[i:i+len(sub_string)]==sub_string: count+=1 except IndexError: break return count
Find a string Writing one line but hard to undestand code is not considered a good programming practice.You will grasp when you gradually become mastered in Python.However I think writing this type of things only for fun is most suitable....