Get duplicates from an array So, I have an array

['a', 42, 'b', 42, 'a']


I want to alert users to the fact that 42 and 'a' appear in it twice.

some_function(['a', 42, 'b', 42, 'a'])


should return

['a', 42]




Write some code to extract the duplicates from an array.


It should accept an array as input.
The array can have multiple types of object.
Duplication should be defined as per the language's standard equality function (examples are from ruby).
It outputs an array of the duplicated items.
The order of the returned items is irrelevant.
Duplicates should only appear in the returned array once.
Golf rules, do it in the smallest number of bytes.


Test cases

[1,2,3] =&gt; []

[1,2,3,2,1] =&gt; [1,2]

[1.0, 2, 2.0, 1.0] =&gt; [1, 2] or [1.0, 2.0] or [1, 2.0] or [1.0, 2]

[1, '1', '1.0'] =&gt; []

[nil, nil, false, false, true, true] =&gt; [nil, false, true]
Python 2, 39 38 bytes



lambda l:{v for v in l if~-l.count(v)}


Try it online!



Python 3, 37 bytes



lambda l:[*map(l.remove,{*l})]and{*l}


Try it online!