finding items that occur more than once in a list

sturlamolden sturlamolden at yahoo.no
Tue Mar 18 17:22:53 EDT 2008


On 18 Mar, 10:57, Simon Forman <sajmik... at gmail.com> wrote:

> 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)


def nonunique(lst):
   slst = sorted(lst)
   return list(set([s[0] for s in
      filter(lambda t : not(t[0]-t[1]), zip(slst[:-1],slst[1:]))]))







More information about the Python-list mailing list