title: Find Max consecutive occurrences on a String Python
body: <p>I need to find the Max consecutive occurrences on a String based on the condition that they can count as more than one if they are consecutive if we have a match of the same word inside of the same sequence but is not consecutive doesn't count, here is an example:</p>
  <pre><code>sequence = &quot;ababcbabc&quot;
  words = [&quot;ab&quot;, &quot;babc&quot;, &quot;bca&quot;]
  </code></pre>
  <p>output:</p>
  <pre><code>[2, 2, 0]
  </code></pre>
  <p>because we can see that 'ab' is actually repeated 3 times on the sequence string, however the condition says that the third one doesn't count because is not consecutive, the same rule apply for 'babc' and 0 if the evaluated word doesn't exist like in the case of 'bca, i have tried with sequence.find but only gives me where the first occurrence starts which is not very convenient to evaluated if the occurrences are together or not, same thing with sequence.rfind, sequence.count gives me all the occurrences but without any condition with .count i get output = [3, 2], also tried with re.findall re.finditer</p>
  <p>in case we have a sequence like this 'abrtfhg' since there is only one match that count as 1 so the output on this case should be: [1,0, 0]</p>
  <pre><code>def maxKOccurrences(sequence, words):
      result = []
      for i in words:
          if i in sequence:
              index_word = sequence.count(i)
              result.append(index_word)
          else:
              result.append(0)
      print(result)
  
  x = &quot;ababcbabc&quot;
  y = [&quot;ab&quot;, &quot;babc&quot;, &quot;bca&quot;]
  maxKOccurrences(x, y)
  </code></pre>