In Python, we can get the unique items of the list using set(list). However doing this breaks the order in which the values appear in the original list. Is there an elegant way to get the unique items in the order in which it appears in the list.
解决方案
This is an elegant way:
from collections import OrderedDict
list(OrderedDict.fromkeys(list))
It works if the list items are all hashable (you will know that all the list items are hashable if converting it to a set did not trigger an exception).
If any items are not hashable, there's an alternative which is more robust at the price of poorer performance: I refer you to the answer from Patrick Haugh.