Finding indices from list comprehension in Python 3
<p>I want to find the indices of matches in a list using the best Python syntax.  Here is what I have:</p>

<pre><code>v = ['=', 'c', '=', 'c', 'c', 'c', '=', 'c', 'c', '=']
</code></pre>

<p>Now, return the list of integers for the condition of:</p>

<pre><code>'=' in v is True
</code></pre>

<p>So far, I have:</p>

<pre><code>[v.index(i) for i in v if i=='=']
</code></pre>

<p>which return:</p>

<pre><code>[ 0, 0, 0, 0 ]
</code></pre>

<p>instead of:</p>

<pre><code>[ 0, 2, 6, 9 ]
</code></pre>

<p>I'm missing the last step and I don't want to put it into a 'for' loop'.</p>

<p>Use <a href="https://docs.python.org/3.5/library/functions.html#enumerate" rel="nofollow"><code>enumerate</code></a>:</p>

<pre><code>[i for i,x in enumerate(v) if x=='=']
</code></pre>

python if-statement list-comprehension