Function that takes list input, and returns a new list containing only the elements in that are repeated

Viewed 31
>>> list_a = ['a', 'b', 'c', 'c']
>>> get_repeated(list_a)
['c']

What would be the most pythonic way to do function get_repeated()?

1 Answers

this should work

from collections import Counter

list_a = ['a', 'b', 'c', 'c']
count = Counter(list_a)
output = [key for key, val in count.items() if val > 1]
print(output)
>>> ['c']
Related