Changes between Version 3 and Version 4 of LambdaSetOperations


Ignore:
Timestamp:
Jan 19, 2010, 4:22:05 PM (10 years ago)
Author:
flip
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • LambdaSetOperations

    v3 v4  
    3535
    3636{{{
     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
    3744    # 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)
    4246    set([0, 1, 2, 3, 4, 5, 6])
    43     >>> print list(union)
    44     [0, 1, 2, 3, 4, 5, 6]
    45    
     47
    4648    # Intersection
    47     >>> intersection = set(list1).intersection(list2)
    48     >>> print intersection
     49    >>> print set(set1).intersection(set2)
    4950    set([3, 4])
    50     >>> print list(intersection)
    51     [3, 4]
    5251
    5352    # Difference
    54     >>> difference = set(list1) - set(list2)
    55     >>> print difference
     53    >>> set1 - set2
    5654    set([0, 1, 2])
    5755
    5856    # Symmetric difference
    5957    # 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)
    6259    set([0, 1, 2, 5, 6])
    6360    >>>