Deleting list elements whilst iterating over it
<p>I need to delete elements from a list whilst iterating over it (I cannot create a new list as it is referenced in code I have no control over).</p>

<p>The best I've come up with is:</p>

<pre><code>last_index = len(somelist) - 1
for (index,item) in enumerate(reversed(somelist)):
    if somecondition(item):
        del somelist[last_index - index]
</code></pre>

<p>Are there better alternatives? I've seen this <a href="http://stackoverflow.com/questions/6022764/python-removing-list-element-while-iterating-over-list">post</a> and this <a href="http://stackoverflow.com/questions/7573115/delete-item-from-list-in-python-while-iterating-over-it">one</a> too, but none of the solutions provided are as efficient or as concise (IMHO).</p>
