How can I find the position in a list where an item differs from the previous item?
<pre><code>l1 = [1,2,2,2]
</code></pre>

<p>In the list above, I know that the element differs in l1[0]. Is there any way to find the position in python?</p>

<p>Assuming you need to show indexes of <strong><em>all</em></strong> occurrences where items change:</p>

<pre><code>l = [1 ,2, 2, 3, 3, 1, 1]

changes = [i for i, n in list(enumerate(l))[1:] if l[i] != l[i-1]]

print(changes)
&gt; [1, 3, 5]
</code></pre>

<p>This simply compares each item from the list with the previous one, lists where elements differ.</p>

python