Comparing two list and getting a new list in python
<p>I have a list - a and a list of columns - b.</p>

<pre><code>a = [2, 4, 1, 1, 6, 1, 1, 3, 5, 1]
b = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"]
</code></pre>

<p>I want to take the columns from list "b" which when compared with list "a" have the value 1.</p>

<p>I want the output to be:</p>

<pre><code>c = ["C", "D", "F", "G", "J"]
</code></pre>

<p>How can I do it?</p>

<p>I'd do it with zip and list comprehension.</p>

<pre><code>&gt;&gt;&gt; a = [2, 4, 1, 1, 6, 1, 1, 3, 5, 1]
&gt;&gt;&gt; b = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"]
&gt;&gt;&gt; c = [x[0] for x in zip(b, a) if x[1] == 1]
&gt;&gt;&gt; c
['C', 'D', 'F', 'G', 'J']
&gt;&gt;&gt;
</code></pre>

python list