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>Try this: </p>

<pre><code>l1.index(min(set(l1), key=l1.count))
</code></pre>

<p>EDIT:</p>

<p>The lambda expression <code>min(set(l1), key=l1.count)</code> tells us what is the element that occurs the fewest number of times in the list. Then we use <code>l1.index</code> to figure out the position of that element in the list.</p>

python