seen = set()
n = iter(range(len(L) - 1, -2, -1))
for x in range(len(L) - 1, -1, -1):
    item = L[x]
k = key(item)
if k not in seen:
    seen.add(k)
L[next(n)] = item
L[:next(n) + 1] = []
Most efficient way to remove duplicates from Python list while preserving order and removing the oldest element