Changes between Version 3 and Version 4 of LambdaSetOperations
 Timestamp:
 Jan 19, 2010, 4:22:05 PM (10 years ago)
Legend:
 Unmodified
 Added
 Removed
 Modified

LambdaSetOperations
v3 v4 35 35 36 36 {{{ 37 # Sets are easy to create from lists: 38 >>> set1 = set(range(5)) 39 >>> set2 = set(range(3,7)) 40 # And back again: 41 >>> list(set2) 42 [3, 4, 5, 6] 43 37 44 # Union 38 >>> list1=range(5) # [0,1,2,3,4] 39 >>> list2=range(3,7) # [3,4,5,6] 40 >>> union = set(list1).union(list2) 41 >>> print union 45 >>> print set1.union(set2) 42 46 set([0, 1, 2, 3, 4, 5, 6]) 43 >>> print list(union) 44 [0, 1, 2, 3, 4, 5, 6] 45 47 46 48 # Intersection 47 >>> intersection = set(list1).intersection(list2) 48 >>> print intersection 49 >>> print set(set1).intersection(set2) 49 50 set([3, 4]) 50 >>> print list(intersection)51 [3, 4]52 51 53 52 # Difference 54 >>> difference = set(list1)  set(list2) 55 >>> print difference 53 >>> set1  set2 56 54 set([0, 1, 2]) 57 55 58 56 # Symmetric difference 59 57 # Return a new set with elements in either the set or other but not both. 60 >>> symmetric_difference = set(list1).symmetric_difference(list2) 61 >>> print symmetric_difference 58 >>> print set1.symmetric_difference(set2) 62 59 set([0, 1, 2, 5, 6]) 63 60 >>>