Best way to eliminate duplicates in a list, but keep previous relative order
Question: > **Possible Duplicate:**  
>  [How do you remove duplicates from a list in Python whilst preserving
> order?](http://stackoverflow.com/questions/480214/how-do-you-remove-
> duplicates-from-a-list-in-python-whilst-preserving-order)  
>  [Does Python have an ordered
> set?](http://stackoverflow.com/questions/1653970/does-python-have-an-
> ordered-set)

I find myself doing the following quite frequently:

    
    
    list_of_items # I have a list of items
    set(list_of_items) # I want to remove duplicates
    

However, in converting to a `set`, I lose the initial ordering I had in the
list, which is important.

What is the best way to remove duplicates in a list AND keep the initial
(relative) ordering of the list?


Answer: This is somewhat of an abuse of list comprehensions, but:

    
    
    seen = set()
    item_list = [seen.add(item) or item for item in item_list if item not in seen]
    

