Write a function do_set_operation(set1, set2, set3, item1, item2) that performs a
series of set operations and returns a list of eight results. set1 is updated in
place as you go; set2 and set3 are never modified.
Perform these steps in order, appending the stated value to the result list after each:
item1 to set1, then record sorted(set1).item2 from set1 if it is there (do nothing if it is not), then record
sorted(set1).set2 to set1, then record sorted(set1).set1 every element that is also in set3, then record sorted(set1).set2 and set3, as a sorted list.set1, set2 or set3, as a sorted list.set2 but not in set3, as a sorted list.set2 and set3, as a sorted list.Every result is a sorted list, so the output does not depend on set iteration order.
Example
do_set_operation({1, 2, 3}, {3, 4, 5}, {5, 6, 7}, 9, 2)
-> [[1, 2, 3, 9], [1, 3, 9], [1, 3, 4, 5, 9], [1, 3, 4, 9],
[5], [1, 3, 4, 5, 6, 7, 9], [3, 4], [3, 4, 6, 7]]
Implement this function:
def do_set_operation(set1: set, set2: set, set3: set, item1, item2) -> list:
Write the function only — the arguments are read for you and the return value is printed automatically.
Arguments arrive as one Python literal per line, in this order: set1, set2, set3, item1, item2.
Input
{1, 2, 3}
{3, 4, 5}
{5, 6, 7}
9
2
Output
[[1, 2, 3, 9], [1, 3, 9], [1, 3, 4, 5, 9], [1, 3, 4, 9], [5], [1, 3, 4, 5, 6, 7, 9], [3, 4], [3, 4, 6, 7]]