函数,它接受列表输入,并返回一个仅包含中重复的元素的新列表


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

执行函数get_repeated((的最Python的方法是什么?

这应该能在中工作

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']

最新更新