How to remove index list from another list in python?
<p>I have two long lists. I basically want to remove elements from this list that do not match a condtion. For example,</p>

<pre><code>list_1=['a', 'b', 'c', 'd']

list_2=['1', 'e', '1', 'e']
</code></pre>

<p>List one and two correspond to each other. Now I would like to remove certain elements from list one that do not match my condition. I have to make sure that I remove the corresponding elements from list 2 and the order does not mess up.</p>

<p>So I created a for loop that goes through list 1 and stores all the indices of elements that have to be removed. </p>

<p>Let’s say:</p>

<pre><code>index_list = ['1', '3']
</code></pre>

<p>Basically, I need to make sure I remove b and d from list 1 and e and e from list 2. How do I do this? </p>

<p>I tried:</p>

<pre><code>del (list_1 [i] for i in index_list)]

del (list_2 [i] for i in index_list)]
</code></pre>

<p>But I get an error that indices has to be a list, not list. I also tried:</p>

<pre><code>list_1.remove[i]

list_2.remove[i]
</code></pre>

<p>But this does not work either. I tried creating another loop:</p>

<pre><code>for e, in (list_1):

    for i, in (index_list):

        if e == i:

            del list_1(i)

for j, in (list_2):

    for i, in (index_list):

        if j == i:

            del list_2(i)
</code></pre>

<p>But this does not work either. It gives me an error that e and j are not global names. </p>