 <pre><code>def count_dups(L): ans = [] if not L: return ans running_count = 1 for i in range(len(L)-1): if L[i] == L[i+1]: running_count += 1 else: ans.append(running_count) running_count = 1 ans.append(running_count) return ans </code></pre>