forked from cclauss/Ten-lines-or-less
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset_theory.py
48 lines (45 loc) · 1.7 KB
/
set_theory.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def set_theory(abc, ac, cde):
print("abc: {}\n ac: {}\ncde: {}".format(sorted(abc), sorted(ac), sorted(cde)))
print("Union: abc | cde --> {}".format(sorted(abc | cde)))
print("Intersection: abc & cde --> {}".format(sorted(abc & cde)))
print("Set difference: abc - cde --> {}".format(sorted(abc - cde)))
print("Symmetric difference: abc ^ cde --> {}".format(sorted(abc ^ cde)))
print(
"Is suubset: ac <= abc, abc <= abc --> {}, {}".format(
ac <= abc, abc <= abc
)
) # noqa
print(
"Is superset: abc >= ac, abc >= abc --> {}, {}".format(
abc >= ac, abc >= abc
)
) # noqa
print(
"Is proper suubset: ac < abc, abc < abc --> {}, {}".format(
ac < abc, abc < abc
)
) # noqa
print(
"Is proper superset: abc > ac, abc > abc --> {}, {}".format(
abc > ac, abc > abc
)
) # noqa
if __name__ == "__main__":
# --> ['a', 'b', c'] with duplicate c's will be thrown away
abc = {"a", "b", "c", "c", "c"}
ac = abc - {"b"} # --> ['a', 'c'] with 'b' removed
cde = {"c", "d", "e"}
set_theory(abc, ac, cde)
"""
abc: ['a', 'b', 'c']
ac: ['a', 'c']
cde: ['c', 'd', 'e']
Union: abc | cde --> ['a', 'b', 'c', 'd', 'e']
Intersection: abc & cde --> ['c']
Set difference: abc - cde --> ['a', 'b']
Symmetric difference: abc ^ cde --> ['a', 'b', 'd', 'e']
Is suubset: ac <= abc, abc <= abc --> True, True
Is superset: abc >= ac, abc >= abc --> True, True
Is proper suubset: ac < abc, abc < abc --> True, False
Is proper superset: abc > ac, abc > abc --> True, False
"""