Python - Count the duplicate seq element in array
<p>How to solve this</p>

<pre><code>Input: 2
Array = [2,1,3,2,2,2,1,2,2]
Result : 3 (Max of count of seq of 2)
</code></pre>

<p>I just simply used the for loop, it works fine. But is there any other efficient way?</p>

<pre><code>for i in array:
    if i == input:
        Cnt = Cnt + 1
        if Cnt &gt; Result:
            Result = Cnt;
    else:
      Cnt = 0
</code></pre>

<p>You can use <code>itertools.groupby</code> for this:</p>

<pre><code>from itertools import groupby
max(sum(1 for i in g) for k, g in groupby(array) if k == input)
</code></pre>

python list