Changes between Initial Version and Version 1 of LambdaSetOperations


Ignore:
Timestamp:
Jan 7, 2010, 10:13:35 PM (11 years ago)
Author:
bsoher
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • LambdaSetOperations

    v1 v1  
     1Lambda operators to perform simple set operators
     2
     3{{{
     4        #Example of lambda for simple list AND, OR, XOR, UNION
     5        list1=range(5) # [0,1,2,3,4]
     6        list2=range(3,7) # [3,4,5,6]
     7        union=list1+filter(lambda x:x not in list1,list2)
     8        # union = [0,1,2,3,4,5,6]
     9       
     10        Intersection is just as easy
     11        intersection=filter(lambda x:x in list1,list2)
     12        # intersection=[3,4]
     13
     14        Difference is the last thing you wanted...
     15        difference=filter(lambda x:x not in list2,list1)
     16        # difference=[0,1,2]
     17       
     18        And my set vocabulary is rusty but the distinct elements or those from both lists that are NOT in common (un-intersection?) would be:
     19        distinct=filter(lamba x:x not in list2,list1)+filter(lambda x:x not in list1,list2)
     20        # distinct=[0,1,2,5,6]
     21}}}
     22