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>

<pre><code>for condition, string in zip(index_list, [str_a, str_b, str_c]):
    if condition:
        print string
</code></pre>

<p>Since the question is tagged as <a href="/questions/tagged/python-2.7" class="post-tag" title="show questions tagged &#39;python-2.7&#39;" rel="tag">python-2.7</a>, <a href="https://docs.python.org/2/library/functions.html#zip" rel="nofollow"><code>zip</code></a> produces a new list of tuples. If you have a large list of indexes and strings, consider using <a href="https://docs.python.org/2/library/itertools.html#itertools.izip" rel="nofollow"><code>itertools.izip</code></a>, or upgrade to python 3.</p>

<p><a href="http://stackoverflow.com/a/39568508/2681632">This answer</a> provides a standard lib function exactly for this pattern, removing the need for explicit condition checking.</p>

python python-2.7