What is the best option to retrieve only non-duplicate elements from a Python list? Say I have the following list:
lst = [1, 2, 3, 2, 3, 4]
I w
Use collections.Counter to get counts of items. Combine with a list comprehension to keep only those that have a count of one.
>>> from collections import Counter >>> lst = [1, 2, 3, 2, 3, 4] >>> [item for item, count in Counter(lst).items() if count == 1] [1, 4]