Print all non-unique items in a python list preserving the order
This question was asked to me in an interview and actually took me quite a while to figure out since I wasn't really familiar with awesomeness that is python. Here is a one line implementation. Basically, filter out all the values whose count is greater than one
# print the number in a list if its non unique # eg l = [1,2,3,4,4,4,5,1,2,7,8,8,10] will give [1, 2, 4, 4, 4, 1, 2, 8, 8] def printNonUnique(l): return filter( lambda x: x if l.count(x)>1 else None,l)