Is there any inbuilt way to print duplicate elements present in a python list.
I can write program for the same.
All I'm searching for is if there is any inbuilt method or something for the same.
For Ex:
For input [4,3,2,4,5,6,4,7,6,8]
I need op 4,6
Possibly related duplicate question: How do I find the duplicates in a list and create another list with them?
Simple Answer:
There is the
Counter
class fromcollections
that does the trickwith simple built-in function you can do :
Here is a simple demo
So here is how it works.Iterate over every items in
x
.If the current iteration item doesn't exist iny
append it