How can I find the duplicates in a Python list and create another list of the duplicates? The list only contains integers.
list2 = [1, 2, 3, 4, 1, 2, 3] lset = set() [(lset.add(item), list2.append(item)) for item in list2 if item not in lset] print list(lset)