:param first set: a set of numbers :param second set: a set of numbers :return: the nth number in Sylvester's sequence >>> sumset({1, 2, 3}, {4, 5, 6}) {5, 6, 7, 8, 9} >>> sumset({1, 2, 3}, {4, 5, 6, 7}) {5, 6, 7, 8, 9, 10} >>> sumset({1, 2, 3, 4}, 3) Tracebac
(set_a: set, set_b: set)
| 9 | |
| 10 | |
| 11 | def sumset(set_a: set, set_b: set) -> set: |
| 12 | """ |
| 13 | :param first set: a set of numbers |
| 14 | :param second set: a set of numbers |
| 15 | :return: the nth number in Sylvester's sequence |
| 16 | |
| 17 | >>> sumset({1, 2, 3}, {4, 5, 6}) |
| 18 | {5, 6, 7, 8, 9} |
| 19 | |
| 20 | >>> sumset({1, 2, 3}, {4, 5, 6, 7}) |
| 21 | {5, 6, 7, 8, 9, 10} |
| 22 | |
| 23 | >>> sumset({1, 2, 3, 4}, 3) |
| 24 | Traceback (most recent call last): |
| 25 | ... |
| 26 | AssertionError: The input value of [set_b=3] is not a set |
| 27 | """ |
| 28 | assert isinstance(set_a, set), f"The input value of [set_a={set_a}] is not a set" |
| 29 | assert isinstance(set_b, set), f"The input value of [set_b={set_b}] is not a set" |
| 30 | |
| 31 | return {a + b for a in set_a for b in set_b} |
| 32 | |
| 33 | |
| 34 | if __name__ == "__main__": |
nothing calls this directly
no outgoing calls
no test coverage detected