Removing duplicates from list: Keeping the order and the last duplicate of each element
<p>I have a ordered list with duplicates (objects that compare equal) and I want to remove the duplicates. As I want to keep the order, I cannot use <code>set</code>.</p>

<p>The duplicates in my list don't ocurr directly after each other and I want to keep the last ocurrence. In <a href="https://stackoverflow.com/questions/480214/how-do-you-remove-duplicates-from-a-list-in-whilst-preserving-order">this related post</a>, it seems like only the first ocurrence of a duplicate is kept.</p>

<p>As I simplified example, this is what I want:</p>

<pre><code>list_with_duplicates = [1, 2, 1, 3, 2, 1]
list_without_duplicates = [3, 2, 1]
</code></pre>

<p>The only thing I can think of is a messy implementation using multiple iterations to first save the last ocurrence of each duplicate and then recreating the original list using the order of the last ocurring duplicates.</p>