How do I remove 'None' items from the end of a list in Python : <p>A have a list that might contain items that are None. I would like to remove these items, but only if they appear at the end of the list, so:</p>

<pre class="lang-py prettyprint-override"><code>[None, "Hello", None, "World", None, None]
# Would become:
[None, "Hello", None, "World"]
</code></pre>

<p>I have written a function, but I'm not sure this is the right way to go about it in python?:</p>

<pre class="lang-py prettyprint-override"><code>def shrink(lst):
    # Start from the end of the list.
    i = len(lst) -1
    while i &gt;= 0:
        if lst[i] is None:
            # Remove the item if it is None.
            lst.pop(i)
        else:
            # We want to preserve 'None' items in the middle of the list, so stop as soon as we hit something not None.
            break
        # Move through the list backwards.
        i -= 1
</code></pre>

<p>Also a list comprehension as an alternative, but this seems inefficient and no more readable?:</p>

<pre class="lang-py prettyprint-override"><code>myList = [x for index, x in enumerate(myList) if x is not None or myList[index +1:] != [None] * (len(myList[index +1:]))]
</code></pre>

<p>What it the pythonic way to remove items that are 'None' from the end of a list?</p>
