How can I find the duplicates in a Python list and create another list of the duplicates? The list only contains integers.
the third example of the accepted answer give an erroneous answer and does not attempt to give duplicates. Here is the correct version :
number_lst = [1, 1, 2, 3, 5, ...]
seen_set = set()
duplicate_set = set(x for x in number_lst if x in seen_set or seen_set.add(x))
unique_set = seen_set - duplicate_set