Find a string

  • + 6 comments

    In a list comprehension, we slide through bigger string by one position at a time with the sliding window of length of smaller string. We can compute the sliding count by substracting the length of smaller string from bigger string. For each slide, we compare that part of bigger string with our smaller string and generate 1 in a list if match found. Sum of all of these 1's in a list will give us total number of matches found.

    Definitely, this code is difficult to understand because I tried to solve it in minimum number of lines just for fun. In office, I probably wouldn't code like this:-).