List comprehension confusion
<p>I'm slightly confused by a problem that I'm having and wondered if anyone could help (it seems trivial in my mind so I hope that it genuinely is!)</p>

<p>Basically, I have filtered by a list via the following list comprehension:</p>

<pre><code>depfilt = [s for s in department if 'author' not in s]
</code></pre>

<p>(where department had 154 elements and the resulting depfilt has 72 elements)</p>

<p>Now, I also had a separate list of iD values with 154 elements (<code>subj</code>), for which the indices of this list match those in <code>department</code>. I wanted to retain the correct iD values after the filtering process so used the following line of code:</p>

<pre><code>subfilt = [s for s in subj if 'author' not in department[subj.index(s)]]
</code></pre>

<p>In my mind, I feel this should've worked, but subfilt is actually returning 106 list elements, rather than 72.</p>

<p>Does anybody have any idea why?</p>

<p>Thanks</p>

<p>Use <code>enumerate</code> instead of <code>index</code> in case of duplicate values</p>

<pre><code>[s for i, s in enumerate(subj) if 'author' not in department[i]]
</code></pre>

python