finding items that occur more than once in a list

Simon Forman sajmikins at gmail.com
Tue Mar 18 05:57:06 EDT 2008


Is there a more efficient way to do this?

def f(L):
    '''Return a set of the items that occur more than once in L.'''
    L = list(L)
    for item in set(L):
        L.remove(item)
    return set(L)


|>> f([0, 0, 1, 1, 2, 2, 3])
set([0, 1, 2])






More information about the Python-list mailing list