Set Operations
Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.
Below is a Python program, split up into several pieces. After each
program, submit the value that would be associated with the variable answer
. Note: the checker accepts valid python objects so if the answer is a string it must be wrapped in quotation marks.
If the program in question would cause an error, write error (no quotes!) in the box.
a = {1, 2, 3, 4, 4, 4}
b = {'my_key': a}
b['my_key'].add(5)
answer = len(a)
a = set("hello")
answer = "hello" in a
a = set([1, 2, [3, 4]])
answer = [3, 4] in a
answer = len({"a", 1, 2,} | { 2, 3, 4, "a"})
answer = len({"a", 1, 2,} - { 2, 3, 4, "a"})
answer = len({"a", 1, 2,} & { 2, 3, 4, "a"})
Relevant Reading - Common Iterable Operations
answer = min({"a", 1, 2,} & { 2, 3, 4, "a"})
answer = sum(set([1, 2, 3, 3, 3, 3, 3,]))
answer = min(set("hellogoodbye".upper()))
a = {3, 4, 5, 1}
answer = max(len(a), min(a))
a.add(2)
print(answer)
a = {3, 4, 5, 1}
answer = sorted(a)
Next Exercise: Reverse