How can I print a string depending on the list value?
<p>I want to print a string depending on the values in the list. Values can be 0 or 1. For example:</p>

<pre><code># Example [a,b,c] = [0,0,1] -- &gt; print str c
# [1,0,1] -- print str a and str c

index_list = [0,0,1] # Example      
str_a = "str_a"
str_b = "str_b"
str_c = "str_c"

print str
</code></pre>

<p>Here's an elegant way. Use the compress function in itertools:</p>

<pre><code>import itertools as it
l1 = [1, 0, 1]
l2 = ["a", "b", "c"]
for item in it.compress(l2, l1):
    print item
</code></pre>

<p>Output:</p>

<pre><code>=================== RESTART: C:/Users/Joe/Desktop/stack.py ===================
a
c
&gt;&gt;&gt;
</code></pre>

python python-2.7