ordered sets operations on lists..

Kay Schluehr kay.schluehr at gmx.net
Mon Feb 13 02:30:28 EST 2006


Bengt Richter wrote:

> Perhaps newbies should be advised that
>
>     [x for x in l1 if x in set(l2)]

But the resulting list is a representative of bag not a set ( contains
multiple occurrences of  elements ):

>>> [x for x in [3, 3] if s in Set([3])]
[3,3]

Same with Raymonds solution:

>>> filter(Set([3]).__contains__, [3,3]) 
[3, 3]

Kay




More information about the Python-list mailing list