Print string without a certain word?
<p>So, if I have code like this:</p>

<pre><code>a = ["a", "b", "c", "null"] 

print a
</code></pre>

<p>The number of <code>"null"</code>s varies in the output quite a lot for some reason.
How could I print <code>a</code> without the <code>"null"</code>?</p>

<p>Just iterate through your list to print out everything that does not equal to "null"</p>

<pre><code>a = ["a", "b", "c", "null"] 

for data in a:
    if data != "null":
        print(data)
</code></pre>

<p>If you were looking to filter out data you don't want in your data structure, however, then, the easiest way to do this is to do this in a list comprehension that will remove unwanted "null"</p>

<pre><code>res = [data for data in a if data != "null"]
</code></pre>

python python-2.7 printing