30 seconds of python

  Back to Home

filter_non_unique

listbeginner

Filters out the non-unique values in a list.

Use list comprehension and list.count() to create a list containing only the unique values.

def filter_non_unique(lst):
  return [item for item in lst if lst.count(item) == 1]