Removing all empty elements from a list
<p>Why does my code not remove the last empty element in the list?</p>

<pre><code>templist = ['', 'hello', '', 'hi', 'mkay', '', '']

for element in templist:
    if element == '':
        templist.remove(element)

print (templist)
</code></pre>

<p>Output:</p>

<pre><code>['hello', 'hi', 'mkay', '']
</code></pre>