I know this is probably an easy answer but I can\'t figure it out. What is the best way in Python to keep the duplicates in a list:
x = [1,2,2,2,3,4,5,6,6,7
This is a short way to do it if the list is sorted already:
x = [1,2,2,2,3,4,5,6,6,7] from itertools import groupby print [key for key,group in groupby(x) if len(list(group)) > 1]