[Baypiggies] list question

Tung Wai Yip tungwaiyip at yahoo.com
Wed Apr 6 05:11:43 CEST 2011


Use collections.Counter. Pick those items with count > 1.

http://docs.python.org/dev/library/collections.html#collections.Counter

Wai Yip


> i have this list:
> x = ['cat','dog','dog']
>
> i wish to identify the non-unique element in this list i.e. 'dog'. how  
> do i
> do this?
>
> i did this:
>
>>>> y = list(set(x))
>>>> y
> ['dog', 'cat']
>
> but now i don't know to proceed further. have tried the following:
>
>>>> z = [i for i in x if i in y]
>>>> z
> ['cat', 'dog', 'dog']
>
>>>> z = x - y
> Traceback (most recent call last):
>   File "<pyshell#5>", line 1, in <module>
>     z = x - y
> TypeError: unsupported operand type(s) for -: 'list' and 'list'


More information about the Baypiggies mailing list