Andrew Scheller
11 years ago
7 changed files with 28 additions and 53 deletions
@ -1,5 +1,3 @@ |
|||
s = {1, 2, 3, 4} |
|||
print(s.add(5)) |
|||
l = list(s) |
|||
l.sort() |
|||
print(l) |
|||
print(sorted(s)) |
|||
|
@ -1,30 +1,26 @@ |
|||
def r(s): |
|||
l = list(s) |
|||
l.sort() |
|||
return l |
|||
sets = [set(), {1}, {1, 2}, {1, 2, 3}, {2, 3}, {2, 3, 5}, {5}, {7}] |
|||
for s in sets: |
|||
for t in sets: |
|||
print(r(s), '|', r(t), '=', r(s | t)) |
|||
print(r(s), '^', r(t), '=', r(s ^ t)) |
|||
print(r(s), '&', r(t), '=', r(s & t)) |
|||
print(r(s), '-', r(t), '=', r(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)) |
|||
print(sorted(s), '-', sorted(t), '=', sorted(s - t)) |
|||
u = s.copy() |
|||
u |= t |
|||
print(r(s), "|=", r(t), '-->', r(u)) |
|||
print(sorted(s), "|=", sorted(t), '-->', sorted(u)) |
|||
u = s.copy() |
|||
u ^= t |
|||
print(r(s), "^=", r(t), '-->', r(u)) |
|||
print(sorted(s), "^=", sorted(t), '-->', sorted(u)) |
|||
u = s.copy() |
|||
u &= t |
|||
print(r(s), "&=", r(t), "-->", r(u)) |
|||
print(sorted(s), "&=", sorted(t), "-->", sorted(u)) |
|||
u = s.copy() |
|||
u -= t |
|||
print(r(s), "-=", r(t), "-->", r(u)) |
|||
print(sorted(s), "-=", sorted(t), "-->", sorted(u)) |
|||
|
|||
print(r(s), '==', r(t), '=', s == t) |
|||
print(r(s), '!=', r(t), '=', s != t) |
|||
print(r(s), '>', r(t), '=', s > t) |
|||
print(r(s), '>=', r(t), '=', s >= t) |
|||
print(r(s), '<', r(t), '=', s < t) |
|||
print(r(s), '<=', r(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) |
|||
print(sorted(s), '<=', sorted(t), '=', s <= t) |
|||
|
@ -1,12 +1,7 @@ |
|||
def report(s): |
|||
l = list(s) |
|||
l.sort() |
|||
print(l) |
|||
|
|||
s = {1, 2, 3, 4} |
|||
report(s) |
|||
report(s.intersection({1, 3})) |
|||
report(s.intersection([3, 4])) |
|||
print(sorted(s)) |
|||
print(sorted(s.intersection({1, 3}))) |
|||
print(sorted(s.intersection([3, 4]))) |
|||
|
|||
print(s.intersection_update([1])) |
|||
report(s) |
|||
print(sorted(s)) |
|||
|
@ -1,12 +1,7 @@ |
|||
def report(s): |
|||
l = list(s) |
|||
l.sort() |
|||
print(l) |
|||
|
|||
s = {1} |
|||
s.update() |
|||
report(s) |
|||
print(s) |
|||
s.update([2]) |
|||
report(s) |
|||
print(sorted(s)) |
|||
s.update([1,3], [2,2,4]) |
|||
report(s) |
|||
print(sorted(s)) |
|||
|
Loading…
Reference in new issue