Filter Unique List Values
Problem
Write a Python function called filter_unique(lst)
that takes a list as an argument and returns a new list with only the non-unique values. To solve this problem, you can follow these steps:
- Use
collections.Counter
to get the count of each value in the list.
- Use a list comprehension to create a list containing only the non-unique values.
Your function should satisfy the following requirements:
- The function should take a list as an argument.
- The function should return a new list with only the non-unique values.
- The function should not modify the original list.
- The function should be case-sensitive, meaning that 'a' and 'A' are considered different values.
def filter_unique(lst):
## your code here
Example
assert filter_unique([1, 2, 2, 3, 4, 4, 5]) == [2, 4]
assert filter_unique(['a', 'b', 'c', 'b', 'd', 'e', 'e']) == ['b', 'e']