Lichen

tests/set.py

934:2989aab1b4f7
13 months ago Paul Boddie Renamed the utf8string class to unicode, eliminating the unicode function. This means that the simple case of merely returning an object if it is already a Unicode object no longer occurs when using the unicode callable, but such behaviour might be better supported with more general customised instantiation functionality.
     1 s = set()     2 s.add(10)     3 s.add(20)     4 s.add("c")     5 s.add((1, 2))     6      7 print "# s:",     8 print s                             # set([10, 20, "c", (1, 2))     9 print len(s)                        # 4    10 print 10 in s                       # True    11 print 20 in s                       # True    12 print "c" in s                      # True    13 print 30 in s                       # False    14 print (1, 2) in s                   # True    15     16 s2 = set([10, 20, "c", (1, 2)])    17     18 print "# s2:",    19 print s2                            # set([10, 20, "c", (1, 2))    20 print len(s2)                       # 4    21 print 10 in s2                      # True    22 print 20 in s2                      # True    23 print "c" in s2                     # True    24 print 30 in s2                      # False    25 print (1, 2) in s2                  # True    26     27 a = set([1, 3, 5, 7, 9])    28 b = set([1, 2, 3, 5, 7])    29     30 aub = a.union(b)    31 aib = a.intersection(b)    32 adb = a.difference(b)    33 asdb = a.symmetric_difference(b)    34     35 print len(aub)                      # 6    36 print len(aib)                      # 4    37 print len(adb)                      # 1    38 print len(asdb)                     # 2    39 print    40 print 1 in aub                      # True    41 print 1 in aib                      # True    42 print 1 in adb                      # False    43 print 1 in asdb                     # True    44 print    45 print 2 in aub                      # True    46 print 2 in aib                      # False    47 print 2 in adb                      # False    48 print 2 in asdb                     # False    49 print    50 print 9 in aub                      # True    51 print 9 in aib                      # False    52 print 9 in adb                      # True    53 print 9 in asdb                     # False    54 print    55     56 aub2 = a.copy()    57 aub2.update(b)    58 print len(aub2)                     # 6    59     60 aib2 = a.copy()    61 aib2.intersection_update(b)    62 print len(aib2)                     # 4    63     64 adb2 = a.copy()    65 adb2.difference_update(b)    66 print len(adb2)                     # 1    67     68 asdb2 = a.copy()    69 asdb2.symmetric_difference_update(b)    70 print len(asdb2)                    # 2