Answer the question
In order to leave comments, you need to log in
How to get only duplicate elements from a list in Python?
It is necessary to write out repeated values from the list - ['test', 'test1', 'test', 'test', 'test2', 'test2']. That is, the result should be - ['test', test2]
Answer the question
In order to leave comments, you need to log in
>>> t = ['test', 'test1', 'test', 'test', 'test2', 'test2']
>>> import collections
>>> print([item for item, count in collections.Counter(t).items() if count > 1])
['test', 'test2']
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question