2015-08-21 06:56:14 -04:00
|
|
|
# test set binary operations
|
|
|
|
|
2014-01-12 18:37:45 -05:00
|
|
|
sets = [set(), {1}, {1, 2}, {1, 2, 3}, {2, 3}, {2, 3, 5}, {5}, {7}]
|
|
|
|
for s in sets:
|
|
|
|
for t in sets:
|
2014-04-07 00:00:03 -04:00
|
|
|
print(sorted(s), '|', sorted(t), '=', sorted(s | t))
|
|
|
|
print(sorted(s), '^', sorted(t), '=', sorted(s ^ t))
|
|
|
|
print(sorted(s), '&', sorted(t), '=', sorted(s & t))
|
|
|
|
print(sorted(s), '-', sorted(t), '=', sorted(s - t))
|
2014-01-12 18:37:45 -05:00
|
|
|
u = s.copy()
|
|
|
|
u |= t
|
2014-04-07 00:00:03 -04:00
|
|
|
print(sorted(s), "|=", sorted(t), '-->', sorted(u))
|
2014-01-12 18:37:45 -05:00
|
|
|
u = s.copy()
|
|
|
|
u ^= t
|
2014-04-07 00:00:03 -04:00
|
|
|
print(sorted(s), "^=", sorted(t), '-->', sorted(u))
|
2014-01-12 18:37:45 -05:00
|
|
|
u = s.copy()
|
|
|
|
u &= t
|
2014-04-07 00:00:03 -04:00
|
|
|
print(sorted(s), "&=", sorted(t), "-->", sorted(u))
|
2014-01-12 18:37:45 -05:00
|
|
|
u = s.copy()
|
|
|
|
u -= t
|
2014-04-07 00:00:03 -04:00
|
|
|
print(sorted(s), "-=", sorted(t), "-->", sorted(u))
|
2014-01-12 18:09:10 -05:00
|
|
|
|
2014-04-07 00:00:03 -04:00
|
|
|
print(sorted(s), '==', sorted(t), '=', s == t)
|
|
|
|
print(sorted(s), '!=', sorted(t), '=', s != t)
|
|
|
|
print(sorted(s), '>', sorted(t), '=', s > t)
|
|
|
|
print(sorted(s), '>=', sorted(t), '=', s >= t)
|
|
|
|
print(sorted(s), '<', sorted(t), '=', s < t)
|
|
|
|
print(sorted(s), '<=', sorted(t), '=', s <= t)
|
2015-08-21 06:56:14 -04:00
|
|
|
|
|
|
|
print(set('abc') == 1)
|
|
|
|
|
|
|
|
try:
|
|
|
|
set('abc') * 2
|
|
|
|
except TypeError:
|
|
|
|
print('TypeError')
|